#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int k,t;
  cin >> k >> t;
  vi a(t);
  int maxnum = 0, pos;
  rep(i, t){
    cin >> a[i];
    if(a[i] > maxnum){
      maxnum = a[i];
      pos = t;
    }
  }
  int ans = maxnum - 1;
  ans = max(ans - k + maxnum, 0);
  cout << ans << endl;
}
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
#include<type_traits>
#include<tuple>
#include<deque>
#include<cassert>
#include<bitset>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(int (i)=0;(i)<(N);(i)++)
#define chmax(x,y) x=max(x,y)
#define chmin(x,y) x=min(x,y)
const double PI = 3.1415926535897932384626433832795;
const int mod = 1000000007;
const int INF = 1001001001;

int dp[400][400];
const int dx[] = {0, 0, 1, -1};
const int dy[] = {1, -1, 0, 0};

int h, w;
vector<vector<bool>> used(400, vector<bool>(400));
ll black = 0, white = 0;

void dfs(int x, int y, vector<string> &s) {
  if (used[x][y]) return;
  used[x][y] = true;
  if (s[x][y] == '.') white++;
  else black++;

  char cur = s[x][y];
  rep(i, 4) {
    int nx = dx[i] + x;
    int ny = dy[i] + y;
    if (0 <= nx && nx < h && 0 <= ny && ny < w) {
      char next = s[nx][ny];
      if (next != cur) {
        dfs(nx, ny, s);
      }
    }
  }
}

int main() {
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];

  ll ans = 0;
  rep(i, h) rep(j, w) {
    black = white = 0;
    dfs(i, j, s);
    ans += black * white;
  }

  cout << ans << endl;
}