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

const int MAX_N = 41;
typedef long long LL;

LL a[1 << (MAX_N / 2)], b[1 << (MAX_N / 2)];
LL item[MAX_N];

int generate_item(LL* s, int beg, int end) {
    int len = 1 << (end - beg);
    for (int i = 0; i < len; i++) {
        for (int j = beg; j < end; j++)
            s[i] += (1 << (j - beg)) & i ? item[j] : 0;
    }
    sort(s, s + len);
    return len;
}

LL GCD(LL x, LL y) {
    return y == 0 ? x : GCD(y, x % y);
}

LL LCM(LL x, LL y) {
    return x * y / GCD(x, y);
}



const int MAX_CHAR_NUM = 4 * 1e5 + 10;
char tmp[MAX_CHAR_NUM];

char get_char(LL p) {
    return p % 3 == 2 ? '0' : '1';
}

vector<int> getNext(const string& s) {
	vector<int> ret(s.length(), 0);
	if (ret.empty()) return ret;
	for (size_t k1(1), kt(0); k1 < ret.size(); ++k1) {
		while (kt && s[kt] != s[k1]) kt = ret[kt - 1];
		if (s[kt] == s[k1]) ++kt;
		ret[k1] = kt;
	}
	return ret;
}

vector<int> kmp(const string& s1, const string& s2) {
	vector<int> ret;
	int sl1(s1.length()), sl2(s2.length());
	if (!(sl1 && sl2)) return ret;
	vector<int> nv2(getNext(s2));
	for (int k1(0), k2(0); k1 < sl1;) {
		if (s1[k1] == s2[k2]) ++k1, ++k2;
		else if (k2) k2 = nv2[k2 - 1];
		else ++k1;
		if (k2 == sl2) ret.push_back(k1 - k2), k2 = nv2[k2 - 1];
	}
	return ret;
}


int match_num(const string& s, const string& t) {
    return kmp(s, t).size();
}


LL get_result(LL l, LL r, const string& t) {
    int len = t.length();

    if (r - l <= len) {
        string s(1, get_char(l));
        return match_num(s, t);
    }

    LL m = (l + r) / 2;

    LL left_result = get_result(l, m, t);
    LL right_result = get_result(m, r, t);
    LL mid_result = 0;

    int left_idx = max(l, m - len);
    int right_idx = min(r, m + len);
//    if (right_idx - left_idx >= len) {
//        for (int i = left_idx; i < right_idx; i++)
//            tmp[i - left_idx] = get_char(i);
//
//        tmp[right_idx - left_idx] = 0;
//
//        string mid_string(tmp);
//
//        mid_result = match_num(mid_string, t);
//    }
//    return mid_result;
    return left_result + right_result + mid_result;
}


int main() {
    LL SRC = 10000000000L;
    int N, p;
    string T;
    cin >> N >> T;

    if (N == 1) {
        cout << ((T[0] == '1') + 1) * SRC << endl;
        return 0;
    }

    tmp[N] = 0;
    for (p = 0; p < 3; p++) {
        for (int i = 0; i < N; i++) tmp[i] = get_char(p + i);
        string S(tmp);
        if (S == T) break;
    }

    if (p == 3) puts("0");
    else {
        cout << SRC - (p + N - 1) / 3 << endl;
    }

    return 0;
}

#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std;
void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan0
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, M;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> M;
	map<int, vector<int>> pawns;
	rep(i, 0, M) {
		int X, Y; cin >> X >> Y;
		pawns[X].push_back(Y);
	}

	set<int> ans;
	ans.insert(N);

	fore(p, pawns) {
		set<int> ng;
		set<int> ok;
		fore(y, p.second) {
			if (ans.count(y - 1)) ok.insert(y);
			else if (ans.count(y + 1)) ok.insert(y);
			else ng.insert(y);
		}
		fore(i, ng) ans.erase(i);
		fore(i, ok)  ans.insert(i);
	}

	cout << ans.size() << endl;
}





