#include <bits/stdc++.h>
//#include <atcoder/all>
#define rep(i,n,a) for(int i = a; i < (int)(n); i++)

using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
template<class T> void chmin(T& a, T b){
    if(a>b) a=b;
} 
int main(){
    int n, m;
    cin >> n >> m;
    vector<ll> a(n), b(m);
    rep(i, n, 0) cin >> a[i];
    rep(i, m, 0) cin >> b[i];

    vector<vector<int>> dp(n+1, vector<int>(m+1, INF));
    int ans=0;
    if(n<m){
        rep(i, n, 0) if(a[i]!=b[i]) ans++;
        ans+=m-n;
    }
    else{
        rep(i, m, 0) if(a[i]!=b[i]) ans++;
        ans+=n-m;
    }

    //cout << ans << " ";

    dp[0][0]=0;

    rep(i, n+1, 0){
        rep(j, m+1, 0){
            if(i>0 && j>0){
                if(a[i-1]==b[j-1]){
                    chmin(dp[i][j], dp[i-1][j-1]);
                }
                else{
                    chmin(dp[i][j], dp[i-1][j-1]+1);
                }
            }
            if(i>0) chmin(dp[i][j], dp[i-1][j]+1);
            if(j>0) chmin(dp[i][j], dp[i][j-1]+1);
        }
    }
    ans=min(ans, dp[n][m]);
    cout << ans;

    return 0;
}
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
typedef pair<ll, ll> P;
#define FOR(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "
#define ALL(n) begin(n),end(n)
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
const ll INF = numeric_limits<ll>::max();
const char clist[4] = {'A', 'T', 'C', 'G'};
int main()
{
    int n; cin >> n;
    string s; cin >> s;

    VI a(n+1), t(n+1), c(n+1), g(n+1);
    rep(i, n) {
        a[i+1] = a[i] + (s[i] == 'A');
        t[i+1] = t[i] + (s[i] == 'T');
        c[i+1] = c[i] + (s[i] == 'C');
        g[i+1] = g[i] + (s[i] == 'G');
    }
    ll ans = 0;
    rep(i, n) {
        for(int l=2; l<=n ; l = l+2) {
            if (i+l > n) continue;
            if ((a[i+l] - a[i] == t[i+l] - t[i])&&(c[i+l] - c[i] == g[i+l] - g[i])) {
                ++ans;
            }
        }
    }
    cout << ans << endl;
    return 0;
}