#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
int main(){
    int h,w,ans=0;
    cin >> h >> w;
    vector<string>s(h);
    rep(i,h)cin >> s[i];
    
    rep(i,h){
        rep(j,w){
            if(j!=w-1 and s[i][j]=='.' and s[i][j+1]=='.')ans++;
            if(i!=h-1 and s[i][j]=='.' and s[i+1][j]=='.')ans++;
        }
    }
    
    cout << ans;
    
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

#define present(container, element) (container.find(element) != container.end())
#define cpresent(container, element) (find(all(container), element) != container.end())
#define INF 0x3f3f3f3f
#define f1(i, n) for (int i = 0; i < n; ++i)
#define f2(i, n) for (int i = 1; i < n; ++i)
#define f3(i, start, end) for (int i = start; i < end; ++i)
#define ll long long
typedef pair<int, int> iPair;
const double epsilon = 1e-7;
ll n, m;
vector<iPair> v;
set<int> s, a, b;
// s: cols reachable currently
// a: cols rechable now onwards
// b: cols unreachable now onwards

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m; 
  int x, y;
  f1 (i, m) {
    cin >> x >> y;
    v.emplace_back(x, y);
  }
  sort(begin(v), end(v));
  s.insert(n);
  f1 (i, m) {
    a.clear(); b.clear();
    int l = i;
    int row = v[i].first;
    while (v[i].first == row) i++;
    i--;
    int r = i;
    for (; l <= r; l++) {
      int col = v[l].second;
      // can reach this col ?
      if (s.count(col+1) or s.count(col-1))
        a.insert(col);
      else b.insert(col);
    }
    for (auto x: b) s.erase(x);
    for (auto x: a) s.insert(x);
  }
  cout << s.size() << endl;
  return 0;
}
