#include<bits/stdc++.h>
#define ll long long
using namespace std;

void solve(){
	int n,m;cin>>n>>m;
	vector<vector<int>>a;
	for(int i=0;i<m;i++){
		int x, y;cin>>x>>y;
		a.push_back({x, y});
	}

	sort(a.begin(), a.end());
	map<int,int>look;
	look[n]++;



	for(int i=0;i<m;){

		int r = a[i][0];
		int j = i;
		map<int,int>cur;

		while(i<m && a[i][0] == r){
			if(look.find(a[i][1]-1) != look.end()){
				cur[a[i][1]]++;
			}
			if(look.find(a[i][1]+1) != look.end()){
				cur[a[i][1]]++;
			}
			i++;
		}
		while(j<m && a[j][0] == r){
			if(look.find(a[j][1]) != look.end()){
				look.erase(a[j][1]);
			}
			j++;
		}

		for(auto x:cur)	look[x.first]++;
	}
	cout<<look.size()<<"\n";
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);
    #ifndef ONLINE_JUDGE    
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout); 
    #endif
   	solve();
    return 0;
}

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int M=1e1+7;
ll h,w,c[M][M],ans;char mp[M][M];
inline ll read(){
	ll w=0,r=1;char c=getchar();
	while(!(isdigit(c)||c=='-'))c=getchar();
	if(c=='-')r=-1,c=getchar();
	while(isdigit(c))w=w*10+c-'0',c=getchar();
	return w*r;
}
int main(){
	h=read(),w=read();
	for(int i=1;i<=h;i++)
		scanf("%s",mp[i]+1);
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(mp[i][j]=='#')c[i][j]=1;
	for(int i=1;i<=h+1;i++)
		for(int j=1;j<=w;j++)
			if(c[i][j]!=c[i-1][j]){
				//printf("*%d %d\n",i,j);
				j++;
				ans++;
				
				while(c[i][j]!=c[i-1][j]&&c[i][j]==c[i][j-1])j++;
				j--;
			}
	for(int j=1;j<=w+1;j++)
		for(int i=1;i<=h;i++)
			if(c[i][j]!=c[i][j-1]){
				//printf("**%d %d\n",i,j);
				i++;
				ans++;
				
				while(c[i][j]!=c[i][j-1]&&c[i][j]==c[i-1][j])i++;
				i--;
			}
	printf("%lld\n",ans);
	return 0;
}
/*
5 5
.....
.###.
.###.
.###.
.....

4 4
.#.#
#.#.
.#.#
#.#.
*/