#include<bits/stdc++.h>
using namespace std;
int n, m;
string s;
bool k1, k2, k3;
int main() {
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    freopen("game.in", "r", stdin);
    freopen("game.out", "w", stdout);
    cin >>n;
    cin >>m;
    cin >>s;
    s = "1" + s + "1";
    for (int i = 1; i + 1 < s.size(); ++i){
        int l = i, r = i;
        while (s[l - 1] == s[i] && r - l + 1 <= 3)l--;
        while (s[r + 1] == s[i] && r - l + 1 <= 3)r++;
        if (r - l + 1 == 1)k1 = 1;
        if (r - l + 1 == 2)k2 = 1;
        if (r - l + 1 == 3)k3 = 1;
    }
    if (k1 && k2 && k3)return cout <<(n + 3 - 1) / 3, 0;
    if (k1 && k2)return cout <<(n + 2 - 1) / 2, 0;
    if (k1 && k3)return cout <<n / 3 + n % 3, 0;
    if (k2 && k3){
        if (n == 1)return cout <<-1, 0;
        if (n % 3 == 0)return cout <<n / 3, 0;
        cout <<n / 3 + 1;
        return 0;
    }
    if (k1)return cout <<n, 0;
    if (k2){
        if (n % 2 == 1)return cout <<-1, 0;
        cout <<n / 2;
        return 0;
    }
    if (k3){
        if (n % 3 != 0)return cout <<-1, 0;
        cout <<n / 3;
        return 0;
    }
    cout <<-1;
}

