#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#include "bits/stdc++.h"
using namespace std;
using i64 = long long;
const i64 MOD = 1e9+7;
const i64 INF = 1e18+7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


template <i64 mod = MOD>
struct ModInt{
    i64 p;

    ModInt() : p(0){}
    ModInt(i64 x){p = x >= 0 ? x % mod : x + (-x + mod - 1) / mod * mod;}

    ModInt& operator+=(const ModInt& y){p = p + *y - ((p + *y) >= mod ? mod : 0); return *this;}
    ModInt& operator-=(const ModInt& y){p = p - *y + (p - *y < 0 ? mod : 0); return *this;}
    ModInt& operator*=(const ModInt& y){p = (p * *y) % mod; return *this;}
    ModInt& operator%=(const ModInt& y){if(y)p %= *y; return *this;}

    ModInt operator+(const ModInt& y) const{ModInt x = *this; return x += y;}
    ModInt operator-(const ModInt& y) const{ModInt x = *this; return x -= y;}
    ModInt operator*(const ModInt& y) const{ModInt x = *this; return x *= y;}
    ModInt operator%(const ModInt& y) const{ModInt x = *this; return x %= y;}

    friend ostream& operator<<(ostream& stream, const ModInt<mod>& x){
        stream << *x;
        return stream;
    }

    friend ostream& operator>>(ostream& stream, const ModInt<mod>& x){
        stream >> *x;
        return stream;
    }

    ModInt& operator++(){p = (p + 1) % mod; return *this;}
    ModInt& operator--(){p = (p - 1 + mod) % mod; return *this;}

    bool operator==(const ModInt& y) const{return p == *y;}
    bool operator!=(const ModInt& y) const{return p != *y;}

    const i64& operator*() const{return p;}
    i64& operator*(){return p;}

};

using mint = ModInt<>;


auto mpow = [](auto x, i64 y){
 auto z = x;
 decltype(x) val = y & 1 ? x : decltype(x)(1);
 while(z *= z, y >>= 1)
  if(y & 1)
   val *= z;
 return val;
};

template <i64 mod1 = MOD, i64 mod2 = MOD + 2, i64 base = 10007, typename T = string>
struct RollingHash{

    using mint1 = ModInt<mod1>;
    using mint2 = ModInt<mod2>;
    using pair_type = pair<mint1, mint2>;
    int len;
    std::vector<pair_type> v;
    static std::vector<pair_type> power, inv;

    RollingHash(T s) :
    len(s.size())
    {
        v.assign(1, make_pair(mint1(0), mint2(0)));
        for(int i = 0; i < len; ++i){
            auto c = s[i];
            v.emplace_back(v.back().first + power[i].first * c,
                           v.back().second + power[i].second * c);
            if(static_cast<int>(power.size()) == i + 1){
                power.emplace_back(power.back().first * base,
                                   power.back().second * base);
                inv.emplace_back(mpow(power.back().first, mod1 - 2),
                                 mpow(power.back().second, mod2 - 2));
            }
        }
    };

    pair_type get(int l = 0, int r = -1){
        if(r == -1)
            r = len;
        assert(l <= r);
        assert(r <= len);
        auto l_cut = make_pair(v[r].first - v[l].first,
                               v[r].second - v[l].second);
        return make_pair(l_cut.first * inv[l].first,
                         l_cut.second * inv[l].second);
    }

    pair_type connect(pair_type l, pair_type r, int l_len){
        return make_pair(l.first + power[l_len].first * r.first,
                         l.second + power[l_len].second * r.second);
    }
};
using RH = RollingHash<MOD, MOD + 2, 10007>;
template<> vector<pair<ModInt<MOD>, ModInt<MOD + 2>>> RH::power = {make_pair(ModInt<MOD>(1), ModInt<MOD + 2>(1))};
template<> vector<pair<ModInt<MOD>, ModInt<MOD + 2>>> RH::inv = {make_pair(ModInt<MOD>(1), ModInt<MOD + 2>(1))};

i64 rhHash(RH::pair_type& p){
    return *p.first + (*p.second << 32);
}

signed main(){
    int n, q;
    string s;
    cin >> n >> q >> s;

    auto divisor = [](i64 x){
     int sq = sqrt(x) + 1;
     vector<int> ret;
     for(i64 i = 1; i < sq; ++i)
      if(!(x % i)){
       ret.emplace_back(i);
       if(i * i != x)
        ret.emplace_back(x / i);
      }
     sort(ret.begin(), ret.end());
     return ret;
    };

    auto divs = divisor(n);
    int m = divs.size();
    RH rh(s);
    vector<multiset<i64>> hash_multiset(m);
    vector<vector<RH::pair_type>> hash_data(m);
    for(int i = 0; i < m; ++i){
        hash_data[i].resize(n / divs[i]);
        for(int j = 0; j < n / divs[i]; ++j){
            hash_data[i][j] = rh.get(j * divs[i], (j + 1) * divs[i]);
            hash_multiset[i].insert(rhHash(hash_data[i][j]));
        }
    }
    for(int _ = 0; _ < q; ++_){
        int p;
        char c;
        scanf("%d %c", &p, &c);
        --p;
        int ans = n;
        for(int i = 0; i < m; ++i){
            // divs[i]: size
            int idx = p / divs[i];
            int pos = p % divs[i];
            auto rh_data = hash_data[i][idx];
            hash_multiset[i].erase(hash_multiset[i].find(rhHash(rh_data)));
            rh_data.first -= RH::mint1(s[p]) * rh.power[pos].first;
            rh_data.second -= RH::mint2(s[p]) * rh.power[pos].second;
            rh_data.first += RH::mint1(c) * rh.power[pos].first;
            rh_data.second += RH::mint2(c) * rh.power[pos].second;
            hash_data[i][idx] = rh_data;
            hash_multiset[i].insert(rhHash(rh_data));
            if(*hash_multiset[i].begin() == *hash_multiset[i].rbegin()){
                chmin(ans, divs[i]);
            }
        }
        s[p] = c;
        printf("%d\n", ans);
    }
}



Measured memory_bytes: 28316