#include <bits/stdc++.h>
#define ll long long
#define vll vector<ll>
#define mp make_pair
#define pb push_back
#define pll pair<ll,ll>
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define F(i,a,n) for(ll i=a;i<n;i++)
#define fil(ar, val) memset(ar, val, sizeof(ar))
using namespace std;

const int mod = 1000000007;


ll gcd(ll a, ll b) {return (b == 0) ? a : gcd(b, a % b);}
ll lcm(ll a, ll b) {return ((a * b) / (gcd(a, b)));}
ll binpow(ll a, ll b)
{
    a %= mod;
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    res %= mod;
    return res;
}

ll counter(ll n)
{
    ll ct = 0;
    while (n)
    {
        n /= 10;
        ct++;
    }
    return ct;
}

bool prime[10000005];
vector<ll>v;
unordered_map<ll, bool>cp;
void sieve()
{
    memset(prime, 1, sizeof(prime));
    for (ll i = 2; i * i <= 10000001; i++)
    {
        if (prime[i] == 1)
        {
            for (ll j = i * i; j <= 10000001 ; j += i)
            {
                prime[j] = 0;
            }
        }
    }
    prime[1] = 0;
    F(i, 3, 2000005)  // n prime : 1000003
    {
        if (prime[i])
        {
            v.pb(i);
            cp[i] = true;
        }
    }
}

vll vis(2005, 0);
vector<ll>adj[2005];
vector<ll>dis(2005, 0);

ll ct = 0;
void dfs(ll node)
{
    ct++;
    vis[node] = 1;
    for (auto i : adj[node])
    {
        if (!vis[i])
        {
            dfs(i);
        }
    }
}
void bfs(ll node)
{
    vis[node] = 1;
    queue<ll>q;
    q.push(node);
    while (!q.empty())
    {
        ll src = q.front();
        q.pop();
        for (auto i : adj[src])
        {
            if (!vis[i])
            {
                dis[i] = dis[src] + 1;
                vis[i] = 1;
                q.push(i);
            }
        }
    }
}

void i_p()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("op.txt", "w", stdout);
#endif
}

// luba luba dub dub

int main() {

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    i_p();

    int t;
    t = 1;
    // cin >> t;
    while (t--)
    {

        // easy way:
        ll n, m;
        cin >> n >> m;
        F(i, 1, n + 1)
        {
            vis[i] = 0;
        }
        ll x, y;
        F(i, 0, m)
        {
            cin >> x >> y;
            adj[x].pb(y);
        }
        ll ans = 0;
        F(i, 1, n + 1)
        {
            ct = 0;
            dfs(i);
            ans += ct;
            // cout << ct << "\n";
            F(i, 1, n + 1)
            {
                vis[i] = 0;
            }
        }
        cout << ans << "\n";

    }



    return 0;
}

#include<bits/stdc++.h>

using namespace std;

#define oo 1000000000

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<char,int> pci;

int n;
string st,str;

int main(){
	cin >> n;
	cin >> str;

	int cnt =0;

	for(int tam = 2;tam<=n;tam++){
		//cout << "\n" << tam << "\n";
		int at=0,cg=0;
		for(int i=0;i<n;i++){

			//cout << ini << " "
			if(str[i]=='A'){
				at++;
			}

			if(str[i]=='T'){
				at--;
			}

			if(str[i]=='C'){
				cg++;
			}

			if(str[i]=='G'){
				cg--;	
			}

			if(i>=tam){
				if(str[i-tam]=='A'){
					at--;
				}

				if(str[i-tam]=='T'){
					at++;
				}

				if(str[i-tam]=='C'){
					cg--;
				}

				if(str[i-tam]=='G'){
					cg++;	
				}
			}

			//cout << at << " " << cg << "\n";
			if((i>=tam-1) && (at == 0 && cg == 0)){
				cnt++;
			}	
		}
	}

	cout << cnt << "\n";
}
