#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin>>n;
  string s;
  cin>>s;
  int count=0;
  for(int i=0;i<s.length();i++){
  	int a=0,t=0,g=0,c=0;
    for(int j=i;j<s.length();j++){
    	
        switch(s[j]){
        	case 'A':a++; break;
			case 'T':t++; break;
			case 'G':g++; break;
			case 'C':c++; break; 	
		}
        
      	if(a==t && g==c)
      		count++;
          
        
    }
    //cout<<i<<" "<<a<<" "<<c<<" "<<g<<" "<<t<<endl;
  }
  cout<<count<<endl;
return 0;
}
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <climits>

#define rep(i, n) for(int i = 0; i < n; i++)
#define per(i, n) for(int i = n - 1; i >= 0; i--)
using ll = long long;
#define vi vector<int>
#define vvi vector<vi>
#define vl vector<ll>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define mod 1000000007
using namespace std;
template<class T, class U>
T &chmax(T &a, const U &b){ if(a < b) a = b; return a; }
template<class T, class U>
T &chmin(T &a, const U &b){ if(a > b) a = b; return a; }
int main(){
  int n,m;
  cin >> n >> m;
  vector<pii> v(m);
  map<int, int> cnt;
  rep(i, m){
    int x,y;
    cin >> x >> y;
    v[i] = {x, y};
    cnt[x]++;
  }
  sort(all(v));
  int left = 0, right = 0;
  set<int> s{n};
  for(auto x : cnt){
    vi a,b;
    right += x.second;
    for(int i = left; i < right; i++){
      int y = v[i].second;
      if(s.count(y - 1) || s.count(y + 1)) a.push_back(y);
      else b.push_back(y);
    }
    for(int y : a) s.insert(y);
    for(int y : b) s.erase(y);
    left += x.second;
  }
  cout << (int)s.size() << "\n";
}