                #include<bits/stdc++.h>
                #define ll            long long
                #define pb            push_back
                #define ppb           pop_back
                #define si            set <ll>
                #define endl          '\n'
                #define fr            first
                #define sc            second
                #define mii           map<ll ,ll >
                #define msi           map<string,ll >
                #define mis           map<ll , string>
                #define rep(i,a,b)    for(ll  i=a;i<b;i++)
                #define all(v)        v.begin(),v.end()
                #define sort(v)       sort(all(v))
                #define pii           pair<ll ,ll >
                #define vi            vector<ll >
                #define vii           vector<pair<ll , ll >>
                #define vs            vector<string>
                #define sz(x)         (ll )x.size()
                #define M             1000000007
                #define bs            binary_search
                #define mp            make_pair
                #define sp(n)         setprecision(n)
                #define spl           " "
                #define arr(a,n)      rep(i,0,n) cin>>a[i]
                #define mod           998244353
                #define show(a)       for(auto it:a) cout<<it<<" "; cout<<endl;
                #define what_is(x)    cout << #x << " is " << x << endl;
                using namespace std;
                ll modularExponentiation(ll x,ll n,ll mm)
                {
                    ll result=1;
                    while(n>0)
                    {
                        if(n% 2 ==1)
                            result=(result * x)%mm;
                        x=(x*x)%mm;
                        n=n/2;
                    }
                    return result;
                }
                ll fib(ll n)
                {
                  long double phi = (1 + sqrt(5)) / 2;
                  return round(pow(phi, n) / sqrt(5));
                }
                vector<bool> prime(100000,true);
                void SieveOfEratosthenes()
                {
                    prime[0]=false;
                    prime[1]=false;
                    for (ll p=2; p*p<=prime.size(); p++)
                    {
                        if(prime[p] == true)
                        {
                          for (ll i=p*p; i<=prime.size(); i += p)
                            prime[i] = false;
                        }
                    }
                }
                vector<ll> g[1001];
                vector<bool> vis(1001,false);
                void dfs(ll p)
                {

                    vis[p]=true;
                    for(auto it:g[p])
                        if(!vis[it])
                            dfs(it);
                        else {cout<<it<<" ";break;}

                }
                ll min(ll a,ll b)
                {
                    return a<b?a:b;
                }
                ll check(ll n)
                {
                    ll k=sqrt(n);
                    return k*k==n;
                }
                set<ll> primeFactors(ll n)
                {
                    set<ll> st;
                    while (n%2 == 0)
                    {
                        st.insert(2);
                        n = n/2;
                    }
                    for (ll i = 3; i <= sqrt(n); i = i+2)
                    {
                        while (n%i == 0)
                        {
                            st.insert(i);
                            n = n/i;
                        }
                    }
                    if (n > 2)
                        st.insert(n);
                    return st;
                }
                void solve()
                {
                   ll n;
                   cin>>n;
                   vector<ll> mp(1000020,0);
                   rep(i,0,n)
                   {
                    ll t;
                    cin>>t;
                    mp[t]++;
                   }
                   ll res=0;
                   rep(i,0,1000020)
                   {
                    mp[i+1]+=mp[i]/2;
                    if(mp[i]&1) res++;
                   }
                   cout<<res;
                }

                signed main()
                {
                    ios_base::sync_with_stdio(false);
                    cin.tie(0);
                    cout.tie(0);
                    #ifndef ONLINE_JUDGE
                    freopen("input.txt","r",stdin);
                    freopen("output.txt","w",stdout);
                    #endif
                    ll t=1;
                    //cin>>t;
                    while(t--) solve();
                }


                #include<bits/stdc++.h>
                #define ll            long long
                #define pb            push_back
                #define ppb           pop_back
                #define si            set <ll>
                #define endl          '\n'
                #define fr            first
                #define sc            second
                #define mii           map<ll ,ll >
                #define msi           map<string,ll >
                #define mis           map<ll , string>
                #define rep(i,a,b)    for(ll  i=a;i<b;i++)
                #define all(v)        v.begin(),v.end()
                #define sort(v)       sort(all(v))
                #define pii           pair<ll ,ll >
                #define vi            vector<ll >
                #define vii           vector<pair<ll , ll >>
                #define vs            vector<string>
                #define sz(x)         (ll )x.size()
                #define M             1000000007
                #define bs            binary_search
                #define mp            make_pair
                #define sp(n)         setprecision(n)
                #define spl           " "
                #define arr(a,n)      rep(i,0,n) cin>>a[i]
                #define mod           998244353
                #define show(a)       for(auto it:a) cout<<it<<" "; cout<<endl;
                #define what_is(x)    cout << #x << " is " << x << endl;
                using namespace std;
                ll modularExponentiation(ll x,ll n,ll mm)
                {
                    ll result=1;
                    while(n>0)
                    {
                        if(n% 2 ==1)
                            result=(result * x)%mm;
                        x=(x*x)%mm;
                        n=n/2;
                    }
                    return result;
                }
                ll fib(ll n)
                {
                  long double phi = (1 + sqrt(5)) / 2;
                  return round(pow(phi, n) / sqrt(5));
                }
                vector<bool> prime(100000,true);
                void SieveOfEratosthenes()
                {
                    prime[0]=false;
                    prime[1]=false;
                    for (ll p=2; p*p<=prime.size(); p++)
                    {
                        if(prime[p] == true)
                        {
                          for (ll i=p*p; i<=prime.size(); i += p)
                            prime[i] = false;
                        }
                    }
                }
                vector<ll> g[1001];
                vector<bool> vis(1001,false);
                void dfs(ll p)
                {

                    vis[p]=true;
                    for(auto it:g[p])
                        if(!vis[it])
                            dfs(it);
                        else {cout<<it<<" ";break;}

                }
                ll min(ll a,ll b)
                {
                    return a<b?a:b;
                }
                ll check(ll n)
                {
                    ll k=sqrt(n);
                    return k*k==n;
                }
                set<ll> primeFactors(ll n)
                {
                    set<ll> st;
                    while (n%2 == 0)
                    {
                        st.insert(2);
                        n = n/2;
                    }
                    for (ll i = 3; i <= sqrt(n); i = i+2)
                    {
                        while (n%i == 0)
                        {
                            st.insert(i);
                            n = n/i;
                        }
                    }
                    if (n > 2)
                        st.insert(n);
                    return st;
                }
                void solve()
                {
                   ll n;
                   cin>>n;
                   map<ll,ll> mp;
                   rep(i,0,n)
                   {
                    ll t;
                    cin>>t;
                    mp[t]++;
                   }
                   ll res=0;
                   rep(i,0,1000020)
                   {
                    mp[i+1]+=mp[i]/2;
                    if(mp[i]&1) res++;
                   }
                   cout<<res;
                }

                signed main()
                {
                    ios_base::sync_with_stdio(false);
                    cin.tie(0);
                    cout.tie(0);
                    #ifndef ONLINE_JUDGE
                    freopen("input.txt","r",stdin);
                    freopen("output.txt","w",stdout);
                    #endif
                    ll t=1;
                    //cin>>t;
                    while(t--) solve();
                }


                #include<bits/stdc++.h>
                #define ll            unsigned long long
                #define pb            push_back
                #define ppb           pop_back
                #define si            set <ll>
                #define endl          '\n'
                #define fr            first
                #define sc            second
                #define mii           map<ll ,ll >
                #define msi           map<string,ll >
                #define mis           map<ll , string>
                #define rep(i,a,b)    for(ll  i=a;i<b;i++)
                #define all(v)        v.begin(),v.end()
                #define sort(v)       sort(all(v))
                #define pii           pair<ll ,ll >
                #define vi            vector<ll >
                #define vii           vector<pair<ll , ll >>
                #define vs            vector<string>
                #define sz(x)         (ll )x.size()
                #define M             1000000007
                #define bs            binary_search
                #define mp            make_pair
                #define sp(n)         setprecision(n)
                #define spl           " "
                #define arr(a,n)      rep(i,0,n) cin>>a[i]
                #define mod           998244353
                #define show(a)       for(auto it:a) cout<<it<<" "; cout<<endl;
                #define what_is(x)    cout << #x << " is " << x << endl;
                using namespace std;
                ll modularExponentiation(ll x,ll n,ll mm)
                {
                    ll result=1;
                    while(n>0)
                    {
                        if(n% 2 ==1)
                            result=(result * x)%mm;
                        x=(x*x)%mm;
                        n=n/2;
                    }
                    return result;
                }
                ll fib(ll n)
                {
                  long double phi = (1 + sqrt(5)) / 2;
                  return round(pow(phi, n) / sqrt(5));
                }
                vector<bool> prime(100000,true);
                void SieveOfEratosthenes()
                {
                    prime[0]=false;
                    prime[1]=false;
                    for (ll p=2; p*p<=prime.size(); p++)
                    {
                        if(prime[p] == true)
                        {
                          for (ll i=p*p; i<=prime.size(); i += p)
                            prime[i] = false;
                        }
                    }
                }
                vector<ll> g[1001];
                vector<bool> vis(1001,false);
                void dfs(ll p)
                {

                    vis[p]=true;
                    for(auto it:g[p])
                        if(!vis[it])
                            dfs(it);
                        else {cout<<it<<" ";break;}

                }
                ll min(ll a,ll b)
                {
                    return a<b?a:b;
                }
                ll check(ll n)
                {
                    ll k=sqrt(n);
                    return k*k==n;
                }
                set<ll> primeFactors(ll n)
                {
                    set<ll> st;
                    while (n%2 == 0)
                    {
                        st.insert(2);
                        n = n/2;
                    }
                    for (ll i = 3; i <= sqrt(n); i = i+2)
                    {
                        while (n%i == 0)
                        {
                            st.insert(i);
                            n = n/i;
                        }
                    }
                    if (n > 2)
                        st.insert(n);
                    return st;
                }
                void solve()
                {
                   ll n;
                   cin>>n;
                   ll s=0;
                   rep(i,0,n)
                   {
                    ll t;
                    cin>>t;
                    s+=(1<<t);
                   }
                   ll cnt=0;
                   while(n)
                   {
                    cnt+=n&1;
                    n=n>>1;
                   }
                   cout<<cnt;

                }

                signed main()
                {
                    ios_base::sync_with_stdio(false);
                    cin.tie(0);
                    cout.tie(0);
                    #ifndef ONLINE_JUDGE
                    freopen("input.txt","r",stdin);
                    freopen("output.txt","w",stdout);
                    #endif
                    ll t=1;
                    //cin>>t;
                    while(t--) solve();
                }


#include <bits/stdc++.h>
using namespace std;
#define Mod 1000000007

int dp[2000005],dp2[2000005];
int n,k;
char s[1000005];
int lst[27];

int main(){
	scanf("%d%d",&n,&k);
	scanf("%s",s+1);
	int m=strlen(s+1);
	dp[0]=1;
	for(int i=1;i<=m;i++){
		dp[i]=dp[i-1]*2%Mod;
		dp2[i]=dp[i-1];
		if(lst[s[i]-'a']){
			dp[i]=(dp[i]-dp2[lst[s[i]-'a']]+Mod)%Mod;
		}
		lst[s[i]-'a']=i;
		//cerr<<i<<' '<<dp[i]<<endl;
	}
	for(int i=m+1;i<=m+n;i++){
		int minx=Mod,minpos;
		for(int j=0;j<k;j++){
			if(lst[j]<minx){
				minx=lst[j];
				minpos=j;
			}
		}
		dp[i]=dp[i-1]*2%Mod;
		dp2[i]=dp[i-1];
		if(lst[minpos]){
			dp[i]=(dp[i]-dp2[lst[minpos]]+Mod)%Mod;
		}
		lst[minpos]=i;
	}
	printf("%d\n",dp[m+n]);
	return 0;
}


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <list>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>

#define setzero(arr) memset(arr, 0, sizeof(arr))

int ___read_tmp;
#define fi(i, from, to) for(int i = (from); i < (to); i++)
#define fri(i, from, to) for(int i = (from); i >= (to); i--)
#define fa(it, col) for(auto (it) = (col).begin(); (it) != (col).end(); (it)++)
#define fra(it, col) for(auto (it) = (col).rbegin(); (it) != (col).rend(); (it)++)
#define getBit(vv, bit) ((vv & (lol)(1LL << (31 - bit))) == 0LL ? 0 : 1)
#define getBit64(vv, bit) ((vv & (lol)(1LL << (63 - bit))) == 0LL ? 0 : 1)
#define vecits(obj) obj.begin(), obj.end()
#define strip_string(str) (str)[strcspn((str), "\r\n")] = 0;
#define read_int() (scanf("%d ", &___read_tmp), ___read_tmp)
#define MOD 1000000007
#define PI 3.14159265
#define INF 10000000
//#define FILE_IO "peacefulsets"

typedef unsigned long long lol;
typedef  long long slol;
using namespace std;

char t[1010000];
int d[256];
int last[26];

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#elif defined(FILE_IO)
	freopen(FILE_IO ".in", "r", stdin);
	freopen(FILE_IO ".out", "w", stdout);
#endif
	int n, k;
	scanf("%d %d ", &n, &k);
	fgets(t, 1010000, stdin);
	strip_string(t);

	fi(i, 0, 26)
		last[i] = -1;

	int m = strlen(t);
	lol tmp = 1;
	fi(i, 0, m)
	{
		lol add = (tmp + MOD - d[t[i]]) % MOD;
		tmp = (tmp + add) % MOD;
		d[t[i]] = (d[t[i]] + add) % MOD;
		last[t[i] - 'a'] = i;
	}

	fi(i, 0, n)
	{
		char minc = 'a';
		fi(j, 0, k)
		{
			if (last[j] < last[minc - 'a'])
				minc = 'a' + j;
		}

		lol add = (tmp + MOD - d[minc]) % MOD;
		tmp = (tmp + add) % MOD;
		d[minc] = (d[minc] + add) % MOD;
		last[minc - 'a'] = i + m;
	}

	printf("%I64d", tmp);

	return 0;
}


#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif
#include <stdio.h>
#include <algorithm>
#include <functional>
#include <cstring>
#include <map>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <list>
#include <string>
#include <iostream>
#include <fstream>
#include <vector>
#include <stack>

#define setzero(arr) memset(arr, 0, sizeof(arr))

int ___read_tmp;
#define fi(i, from, to) for(int i = (from); i < (to); i++)
#define fri(i, from, to) for(int i = (from); i >= (to); i--)
#define fa(it, col) for(auto (it) = (col).begin(); (it) != (col).end(); (it)++)
#define fra(it, col) for(auto (it) = (col).rbegin(); (it) != (col).rend(); (it)++)
#define getBit(vv, bit) ((vv & (lol)(1LL << (31 - bit))) == 0LL ? 0 : 1)
#define getBit64(vv, bit) ((vv & (lol)(1LL << (63 - bit))) == 0LL ? 0 : 1)
#define vecits(obj) obj.begin(), obj.end()
#define strip_string(str) (str)[strcspn((str), "\r\n")] = 0;
#define read_int() (scanf("%d ", &___read_tmp), ___read_tmp)
#define MOD 1000000007
#define PI 3.14159265
#define INF 10000000
//#define FILE_IO "peacefulsets"

typedef unsigned long long lol;
typedef  long long slol;
using namespace std;

char t[1010000];
int d[256];
int last[26];

int main() {

#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#elif defined(FILE_IO)
	freopen(FILE_IO ".in", "r", stdin);
	freopen(FILE_IO ".out", "w", stdout);
#endif
	int n, k;
	scanf("%d %d ", &n, &k);
	fgets(t, 1010000, stdin);
	strip_string(t);

	fi(i, 0, 26)
		last[i] = -1;

	int m = strlen(t);
	lol tmp = 1;
	fi(i, 0, m)
	{
		lol add = (tmp + MOD - d[t[i]]) % MOD;
		tmp = (tmp + add) % MOD;
		d[t[i]] = (d[t[i]] + add) % MOD;
		last[t[i] - 'a'] = i;
	}

	fi(i, 0, n)
	{
		char minc = 'a';
		fi(j, 0, k)
		{
			if (last[j] < last[minc - 'a'])
				minc = 'a' + j;
		}

		lol add = (tmp + MOD - d[minc]) % MOD;
		tmp = (tmp + add) % MOD;
		d[minc] = (d[minc] + add) % MOD;
		last[minc - 'a'] = i;
	}

	printf("%I64d", tmp);

	return 0;
}


#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
const int N = 1000001;
using namespace std;

int main() {
//    cout << fixed << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    int n, m, k;
    string s;
    cin >> n >> k >> s;
    m = s.size();
    int last[200];
    memset(last, -1, sizeof last);
    for (int i = 0; i < m; i++) {
        last[s[i]] = i;
    }

    pair<int, char> a[k];
    for (int i = 0; i < k; i++) {
        a[i] = mp(last['a' + i], 'a' + i);
    }

    sort(a, a + k);
    int ind = 0;
    for (int i = 0; i < n; i++) {
        s += a[ind].second;
        ind = (ind + 1) % k;
    }

    ll dp[200];
    memset(dp, 0, sizeof dp);
    ll t = 0;
    for (char c : s) {
        ll h = dp[c];
        dp[c] = (t + 1 + mod) % mod;
        t = (t - h + dp[c] + mod) % mod;
    }

    cout << (t + 1) % mod;

}


#include <cstdio>
#include <memory.h>
#include <cstring>
#include <vector>
#include <deque>
#include <cstdlib>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <functional>
#include <iostream>
#include <set>
#include <list>
#include <map>
#include <time.h>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
using namespace std;

typedef long long ll;
typedef unsigned long long llu;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<string, int> psi;
typedef pair<char, int> pci;
typedef pair<int, char> pic;
const ll MOD = (ll)1e9 + 7;
const long double PI = 3.141592653589793238462643383279502884197;

priority_queue<int, vector<int>, greater<int> > pq;
vector<int> v;

int dp[2000001];
char s[2000002];
int n, k, m;
int al[26];

int main() {
	memset(al, -1, sizeof(al));
	scanf("%d %d", &n, &k);
	scanf("%s", s);
	m = strlen(s);

	for (int i = 0; i < m; i++) {
		s[i] -= 'a';
		dp[i] = 1;

		for (int j = 0; j < k; j++) {
			if (al[j] == -1) continue;
			dp[i] = (dp[i] + dp[al[j]]) % MOD;
		}

		al[s[i]] = i;

	}

	int ans = 1;
	for (int i = 0; i < k; i++) {
		if (al[i] == -1) continue;
		ans = (ans + dp[al[i]]) % MOD;
	}
	// printf("%d //", ans);

	for (int i = m; i < n + m; i++) {
		dp[i] = 1;

		int mav = -1, mavi = -1;
		for (int j = 0; j < k; j++)
			if (mav < i - al[j]) {
				mav = i - al[j];
				mavi = j;
			}
		s[i] = mavi;

		for (int j = 0; j < k; j++) {
			if (al[j] == -1) continue;
			dp[i] = (dp[i] + dp[al[j]]) % MOD;
		}

		al[s[i]] = i;
	}

	ans = 1;
	for (int i = 0; i < k; i++) {
		if (al[i] == -1) continue;
		ans = (ans + dp[al[i]]) % MOD;
	}

	printf("%d", ans);
}


#include <bits/stdc++.h>

using namespace std;

void load() {
    #ifndef ONLINE_JUDGE
    freopen(".inp","r",stdin);
    freopen(".out","w",stdout);
    #endif // ONLINE_JUDGE
}

const int N = 1e6 + 123;
int dp[2*N],last[30];
const int Base = 1e9 + 7;
string s;

void Add(int &a , int b) {
    a += b;
    a %= Base;
    if (a < 0) a += Base;
}

void trungtt() {
    int n,k;
    scanf("%d%d",&n,&k);
    cin >> s;
    int m = s.size(); s = ' ' + s;
    dp[0] = 1;
    for (int i = 1 ; i <= m + n ; ++ i) {
        int good = 0;
        if (i > m) {
            for (int j = 0 ; j < k ; ++ j) if (last[good] > last[j]) good = j;
        } else
            good = s[i] - 'a';

        Add(dp[i],dp[i-1]);
        Add(dp[i],dp[i-1]);
        if (last[good]) Add(dp[i],-dp[last[good]-1]);
        last[good] = i;
    }
    printf("%d",dp[n+m]);
}

int main() {
    load();
    trungtt();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define mod 1000000007
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
typedef long long int  ll;
typedef long double  ld;
#define pii pair<ll,ll>
#define pic pair<ll,char>
#define vi vector< ll >
#define vvi vector< vi >
#define vpi vector< pii >
#define vvpi vector< vpi >
#define st  set <ll, greater <ll> >
#define mst  multiset <ll, greater <ll> >
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mapp  unordered_map <ll, ll>
#define ppii pair< pii, pii >
#define test(t) ll t;cin>>t;while(t--)
#define inarr(n) ll arr[n];for(ll i=0;i<n;i++)cin>>arr[i];
#define ingra(m) vvi arr(100005);for(ll i=0;i<m;i++){ll u,v;cin>>u>>v;arr[u].pb(v);arr[v].pb(u);}
#define mem(a,b) memset(a,b,sizeof(a))
#define inn freopen("input.txt", "r", stdin)
#define outt freopen("output.txt", "w", stdout)
#define all(arr) arr.begin(),arr.end()
ll power(ll x,ll y){ll res = 1;while(y){if(y&1) res = (res*x)%mod;y=y/2,x=(x*x)%mod;}return res%mod;}
int main()
{
    fast;
    ll i;
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    ll m = s.length();
    ll arr[n+m];
    ll index[k];
    for(i=0;i<k;i++)
        index[i] = -1;
    for(i=0;i<m;i++)
    {
        index[s[i]-'a'] = i;
        arr[i] = s[i]-'a';
    }
    for(i=m;i<m+n;i++)
    {
        ll j;
        ll val;
        ll mi = 1e18;
        for(j=0;j<k;j++)
        {
            if(index[j]<mi)
            {
                mi = index[j],val=j;
            }
        }
        arr[i] = val;
        index[val] = i;
    }
    ll last[k];
    ll dp[n+1+m];
    for(i=0;i<k;i++)
        last[i] = -1;
    dp[0] = 1;
    for(i=1;i<=m+n;i++)
    {
        dp[i] = (2*dp[i-1])%mod;
        if(last[arr[i-1]]!=-1){
            dp[i] = (dp[i] - dp[last[arr[i-1]]]+mod)%mod;
        }
        last[arr[i-1]] = i-1;
    }
    cout<<dp[m+n];
}


#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define MAXN 1000005
#define INF 1e15
#define REP(i,n) for (ll i=0;i<n;i++)
#define sc(i) scanf("%lld",&i);
#define pr(i) prllf("%lld ",i);
using namespace std;
typedef long long ll;
typedef pair<ll,ll> iPair;
#define _sz(x) (ll)x.size()
typedef vector<vector<ll> > matrix;
const ll MOD = 1000000007;

ll last[26];
int main(){
    memset(last,-1,sizeof(last));
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    ll m=s.length();
    ll dp[m+n+1];
    dp[0]=1;
    for(ll i=0;i<m;i++){
        dp[i+1]=(2*dp[i])%MOD;
        if(last[s[i]-'a']!=-1)
            dp[i+1]=(dp[i+1]-dp[last[s[i]-'a']]+MOD)%MOD;
        last[s[i]-'a']=i;
    }
    for(ll i=m;i<n+m;i++){
        dp[i+1]=(2*dp[i])%MOD;
        ll minidx=1e5;ll c;
        for(ll j=0;j<k;j++){
            if(minidx>last[j]){
                minidx=last[j];
                c=j;
            }
        }
        if(last[c]!=-1){
            dp[i+1]=(dp[i+1]-dp[last[c]]+MOD)%MOD;
        }
        last[c]=i;
    }
    cout<<dp[n+m]%MOD;
}


#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define MAXN 1000005
#define INF 1e15
#define REP(i,n) for (ll i=0;i<n;i++)
#define sc(i) scanf("%lld",&i);
#define pr(i) prllf("%lld ",i);
using namespace std;
typedef long long ll;
typedef pair<ll,ll> iPair;
#define _sz(x) (ll)x.size()
typedef vector<vector<ll> > matrix;
const ll MOD = 1000000007;

ll last[26];
int main(){
    memset(last,-1,sizeof(last));
    ll n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    ll m=s.length();
    ll dp[m+n+1];
    dp[0]=1;
    for(ll i=0;i<m;i++){
        dp[i+1]=(2*dp[i])%MOD;
        if(last[s[i]-'a']!=-1)
            dp[i+1]=(dp[i+1]-dp[last[s[i]-'a']]+MOD)%MOD;
        last[s[i]-'a']=i;
    }
    for(ll i=m;i<n+m;i++){
        dp[i+1]=(2*dp[i])%MOD;
        ll minidx=1e9;ll c;
        for(ll j=0;j<k;j++){
            if(minidx>last[j]){
                minidx=last[j];
                c=j;
            }
        }
        if(last[c]!=-1){
            dp[i+1]=(dp[i+1]-dp[last[c]]+MOD)%MOD;
        }
        last[c]=i;
    }
    cout<<dp[n+m]%MOD;
}


#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)

int an[27], md = 1e9 + 7, k, n;
char s[1000001];

inline int sum() {
	int x = 0;
	f(i, 0, k + 1)if ((x += an[i]) >= md)x -= md;
	return x;
}

inline void mn() {
	pair<int, int> t = make_pair(2e9, 0);
	f(i, 1, k + 1)if (an[i] < t.first)t = make_pair(an[i], i);
	an[t.second] = sum();
}

int main() {
	scanf("%d%d%s", &n, &k, s);
	an[0] = 1;
	for (int i = 0; s[i]; ++i)an[s[i] - 'a' + 1] = sum();
	f(i, 0, n)mn();
	printf("%d", sum());
}


#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)

ll an[27];
int md = 1e9 + 7, k, n;
char s[1000001];
vector<int> cy;
bool vis[27];

inline int sum() {
	int x = 0;
	f(i, 0, k + 1)if ((x += an[i]) >= md)x -= md;
	return x;
}

int main() {
	scanf("%d%d%s", &n, &k, s);
	an[0] = 1;
	int i;
	for (i = 0; s[i]; ++i) {
		s[i] -= 'a' - 1;
		an[s[i]] = sum();
	}
	for (--i; i >= 0; --i)if (!vis[s[i]])vis[s[i]] = true, cy.push_back(s[i]);
	f(i, 1, k + 1)if (!vis[i])cy.push_back(i);
	int j = k - 1;
	f(i, 0, n) {
		if (j == -1)j = k - 1;
		an[cy[j--]] = sum();
	}
	printf("%d", sum());
}


#include<stdio.h>
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i,x,n) for (int i = x;i < n;++i)

ll an[27];
int md = 1e9 + 7, k, n;
char s[1000001];
vector<int> cy;
bool vis[27];

inline int sum() {
	int x = 0;
	f(i, 0, k + 1)if ((x += an[i]) >= md)x -= md;
	return x;
}

int main() {
	scanf("%d%d%s", &n, &k, s);
	an[0] = 1;
	int i;
	for (i = 0; s[i]; ++i) {
		s[i] -= 'a' - 1;
		an[s[i]] = sum();
	}
	for (--i; i > 0; --i)if (!vis[s[i]])vis[s[i]] = true, cy.push_back(s[i]);
	f(i, 1, k + 1)if (!vis[i])cy.push_back(i);
	int j = k - 1;
	f(i, 0, n) {
		if (j == -1)j = k - 1;
		an[cy[j--]] = sum();
	}
	printf("%d", sum());
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll M = 7 + 1e9;
const int MK = 26;

ll ex[MK];
ll lst[MK];
int k;
int get_min() {
    int m = 0;
    for (int i = 0; i < k; i++)
        if (lst[i] < lst[m])
            m = i;
    return m;
}

int main() {
    ios::sync_with_stdio(0);
    int n;
    string s;
    cin >> n >> k;
    cin >> s;
    ll p = 1;
    ll it = 1;
    for (int i = 0; i < s.size(); i++) {
        int c = s[i] - 'a';
        ll cur = p - ex[c];
        ex[c] = (M + ex[c] + cur) % M;
        p = (M + p + cur) % M;
        lst[c] = it++;
    }
    while (n--) {
        int c = get_min();
        ll cur = p - ex[c];
        ex[c] = (M + ex[c] + cur) % M;
        p = (p + cur + M) % M;
        lst[c] = it++;
    }
    cout << p;
}


#include <iostream>
#include <string>
#include <vector>

using namespace std;

typedef long long ll;
const ll M = 7 + 1e9;
const int MK = 26;

ll ex[MK];
ll lst[MK];
int k;
int get_min() {
    int m = 0;
    for (int i = 0; i < k; i++)
        if (lst[i] < lst[m])
            m = i;
    return m;
}

int main() {
    ios::sync_with_stdio(0);
    int n;
    string s;
    cin >> n >> k;
    cin >> s;
    ll p = 1;
    ll it = 1;
    for (int i = 0; i < s.size(); i++) {
        int c = s[i] - 'a';
        ll cur = p - ex[c];
        ex[c] = (ex[c] + cur) % M;
        p = (p + cur) % M;
        lst[c] = it++;
    }
    while (n--) {
        int c = get_min();
        ll cur = p - ex[c];
        ex[c] = (ex[c] + cur) % M;
        p = (p + cur) % M;
        lst[c] = it++;
    }
    cout << p;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n , k,m;
string t;
ll last[30];
ll dp[30];
ll ans;
const ll MOD = 1e9+7;
void doit(ll c)
{
        ans = ((ans - dp[c])%MOD + MOD)%MOD;
        dp[c] = (ans + dp[c] + 1)%MOD;
        ans = (ans + dp[c])%MOD;
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin >> n >> k;
        cin >> t;
        t = "#" + t;
        m = t.size() - 1;
        for(ll i=1;i<=m;i++)
        {
                ll c = t[i] - 'a' + 1;
                doit(c);
                last[c] = i;
        }
        for(ll i=1;i<=n;i++)
        {
                ll p = 1e9;
                ll c = -1;
                for(ll j=1;j<=k;j++)
                {
                        if(p > last[j])
                        {
                                p = last[j];
                                c = j;
                        }
                }
                doit(c);
                last[c] = m+i;

        }
        cout<<(ans+1)%MOD << endl;
        return 0;
}


#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n , k,m;
string t;
ll last[30];
ll dp[30];
ll ans;
const ll MOD = 1e9+7;
void doit(ll c)
{
        ans = ((ans - dp[c])%MOD + MOD)%MOD;
        dp[c] = (ans + dp[c] + 1)%MOD;
        ans = (ans + dp[c])%MOD;
}
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cin >> n >> k;
        cin >> t;
        t = "#" + t;
        m = t.size() - 1;
        for(ll i=1;i<=m;i++)//
        {
                ll c = t[i] - 'a' + 1;
                doit(c);
                last[c] = i;
        }
        for(ll i=1;i<=n;i++)
        {
                ll p = 1e9;
                ll c = -1;
                for(ll j=1;j<=k;j++)
                {
                        if(p > last[j])
                        {
                                p = last[j];
                                c = j;
                        }
                }
                doit(c);
                last[c] = m+i;

        }
        cout<<(ans+1)%MOD << endl;
        return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef pair<int,int> ii;

const int N = 2e6 + 5;
const int mod = 1e9 + 7;

int n,k,m,dp[N],lst[300];
char s[N];

inline int add(int x,int y) {
  return x + y >= mod ? x + y - mod : x + y;
}

inline int mul(int x,int y) {
  return (ll) x * y % mod;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  cin >> n >> k >> (s + 1);
  m = strlen(s + 1);
  dp[0] = 1;
  for (int i = 1 ; i <= m ; i++) {
    dp[i] = mul(dp[i - 1],2);
    if (lst[s[i]] != 0)
      dp[i] = add(dp[i],mod - dp[lst[s[i]] - 1]);
    lst[s[i]] = i;
  }
  for (int i = m + 1 ; i <= n + m ; i++) {
    dp[i] = mul(dp[i - 1],2);
    int mn = 0;
    for (int j = 0 ; j < k ; j++) {
      if (lst[mn + 'a'] > lst[j + 'a'])
        mn = j;
    }
    if (lst[mn + 'a'] != 0)
      dp[i] = add(dp[i],mod - dp[lst[mn + 'a'] - 1]);
    lst[mn + 'a'] = i;
  }
  cout << dp[n + m] << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
const LL MOD=1e9+7;
#define N 30

using namespace std;
int n,k;
LL dp[30],ord[N];
LL sum;
int last[N];

void add(LL &x,LL y){
	x+=y;
	if(x>=MOD)x-=MOD;
}
void append(int c){
	add(sum,-dp[c]+MOD);
	add(dp[c],sum+1);
	add(sum,dp[c]);
}
bool cmp(int a,int b){
	return last[a]<last[b];
}

char s[1000010];
int main(){
	//freopen("in.txt","r",stdin);
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	memset(last,-1,sizeof(last));
	for(int i=0;s[i];++i){
		int c=s[i]-'a';
		last[c]=i;
		append(c);
	}
	iota(ord,ord+k,0);
	sort(ord,ord+k,cmp);
	for(int i=0;i<n;++i){
		int c=ord[i%k];
		append(c);
	}
	printf("%lld\n",(sum+1)%MOD);
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MOD 1e9+7
#define N 30

using namespace std;
int n,k;
LL dp[30],ord[N];
LL sum;
int last[N];

void add(LL &x,LL y){
	x+=y;
	if(x>=MOD)x-=MOD;
}
void append(int c){
	add(sum,-dp[c]+MOD);
	add(dp[c],sum+1);
	add(sum,dp[c]);
}
bool cmp(int a,int b){
	return last[a]<last[b];
}

char s[N];
int main(){
	//freopen("in.txt","r",stdin);
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	memset(last,-1,sizeof(last));
	iota(ord,ord+k,0);
	sort(ord,ord+k,cmp);
	for(int i=0;s[i];++i){
		int c=s[i]-'a';
		last[c]=i;
		append(c);
	}
	for(int i=0;i<n;++i){
		int c=ord[i%k];
		append(c);
	}
	printf("%lld\n",sum+1);
}


#include <bits/stdc++.h>
using namespace std;
#define LL long long
#define MOD 1e9+7
#define N 30

using namespace std;
int n,k;
LL dp[30],ord[N];
LL sum;
int last[N];

void add(LL &x,LL y){
	x+=y;
	if(x>=MOD)x-=MOD;
}
void append(int c){
	add(sum,-dp[c]+MOD);
	add(dp[c],sum+1);
	add(sum,dp[c]);
}
bool cmp(int a,int b){
	return last[a]<last[b];
}

char s[1000010];
int main(){
	//freopen("in.txt","r",stdin);
	scanf("%d%d",&n,&k);
	scanf("%s",s);
	memset(last,-1,sizeof(last));
	for(int i=0;s[i];++i){
		int c=s[i]-'a';
		last[c]=i;
		append(c);
	}
	iota(ord,ord+k,0);
	sort(ord,ord+k,cmp);
	for(int i=0;i<n;++i){
		int c=ord[i%k];
		append(c);
	}
	printf("%lld\n",(sum+1)%MOD);
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N ((ll)2001*1000)
#define K ((ll)30)
#define MOD ((ll)1e9+7)

ll n,k,last[K],dp[N],_last[K];
string s;

int main()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin>>n>>k>>s;n+=(ll)s.size();
	dp[0]=1;
	for(int i=0;i<K;i++)last[i]=-1;
	for(int i=1;i<=s.size();i++)
	{
		dp[i]=2*dp[i-1]-((last[s[i-1]-'a']!=-1)?dp[last[s[i-1]-'a']]:0);dp[i]%=MOD;dp[i]+=MOD;dp[i]%=MOD;
		last[s[i-1]-'a']=i-1;
	}
	for(int i=0;i<k;i++)_last[i]=last[i];
	sort(_last,_last+k);
	ll p=s.size()+1;
	while(p<=n)
	{
		for(int i=0;p<=n && i<k;i++)
		{
			dp[p]=2*dp[p-1]-((_last[i]!=-1)?dp[_last[i]]:0);dp[p]%=MOD;dp[p]+=MOD;dp[p]%=MOD;
			_last[i]=p-1;
			p++;
		}
	}
	cout<<dp[n];
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define int long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10,inf=1e9+10,mod=1e9+7;
int dp[M],last[M],ans=0;
main()
{
	int n,k;
	cin>>n>>k;
	string x;
	cin>>x;
	for(int i=0;i<x.size();i++)
	{
		int ind=x[i]-'a';
		int tmp=(ans-dp[ind])+mod;
		tmp++;
		tmp%=mod;
		dp[ind]+=tmp;
		ans+=tmp;
		ans%=mod;
		dp[ind]%=mod;
		last[ind]=i+1;
	}
	for(int i=1;i<=n;i++)
	{
		int mi,minn=inf;
		for(int j=0;j<k;j++)
		{
			if(last[j]<minn)minn=last[j],mi=j;
		}
		int tmp=ans-dp[mi]+1+mod;
		tmp%=mod;
		ans+=tmp;
		dp[mi]+=tmp;
		dp[mi]%=mod;
		ans%=mod;
		last[mi]=x.size()+i;
	}
	cout<<(ans+1)%mod;
}


#include <bits/stdc++.h>
using namespace std;

const int M = 1e9 + 7;

signed main() {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  string T;
  cin >> T;
  vector<int> dp(256);
  deque<int> dq;
  set<int> bag;
  for (int i = 0; i < T.size(); ++i) {
    for (int j = 'a'; j <= 'z'; ++j) {
      if (j == T[i]) (dp[T[i]] += 1) %= M;
      else (dp[T[i]] += dp[j]) %= M;
    }
  }
  for (int i = T.size() - 1; ~i; --i) {
    if (bag.count(T[i])) continue;
    bag.emplace(T[i]);
    dq.emplace_front(T[i]);
  }
  for (int i = 0; i < N; ++i) {
    if (bag.size() < K) {
      for (int j = 'a'; j - i + 1 <= K && j <= 'z'; ++j) {
        if (bag.count(j)) continue;
        bag.emplace(j);
        dq.emplace_front(j);
      }
    }
    int u = dq.front();
    dq.pop_front();
    dq.emplace_back(u);
    for (int j = 'a'; j - i + 1 <= K && j <= 'z'; ++j) {
      if (j == u) (dp[u] += 1) %= M;
      else (dp[u] += dp[j]) %= M;
    }
  }
  int ans = 1;
  for (int i = 'a'; i <= 'z'; ++i) {
    (ans += dp[i]) %= M;
  }
  cout << ans << endl;
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

const int M = 1e9 + 7;

signed main() {
  ios::sync_with_stdio(false);
  int N, K;
  cin >> N >> K;
  string T;
  cin >> T;
  vector<int> dp(256);
  deque<int> dq;
  set<int> bag;
  for (int i = 0; i < T.size(); ++i) {
    for (int j = 'a'; j - 'a' + 1 <= K && j <= 'z'; ++j) {
      if (j == T[i]) (dp[T[i]] += 1) %= M;
      else (dp[T[i]] += dp[j]) %= M;
    }
  }
  for (int i = T.size() - 1; ~i; --i) {
    if (bag.count(T[i])) continue;
    bag.emplace(T[i]);
    dq.emplace_front(T[i]);
  }
  for (int i = 0; i < N; ++i) {
    if (bag.size() < K) {
      for (int j = 'a'; j - 'a' + 1 <= K && j <= 'z'; ++j) {
        if (bag.count(j)) continue;
        bag.emplace(j);
        dq.emplace_front(j);
      }
    }
    int u = dq.front();
    dq.pop_front();
    dq.emplace_back(u);
    for (int j = 'a'; j - 'a' + 1 <= K && j <= 'z'; ++j) {
      if (j == u) (dp[u] += 1) %= M;
      else (dp[u] += dp[j]) %= M;
    }
  }
  int ans = 1;
  for (int i = 'a'; i <= 'z'; ++i) {
    (ans += dp[i]) %= M;
  }
  cout << ans << endl;
  return 0;
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
#define mod 1000000007
using namespace std;
int n, m;
int ch[26];
int dp[2000100];
int main(){
	scanf("%d %d", &n, &m);
	string a;
	cin >> a;
	int t = a.size();
	memset(ch, -1, sizeof(ch));
	for (int i = 0; i < t; i++) {
		dp[i] = 1;
		for (int y = 0; y < m; y++) {
			if (ch[y] == -1)continue;
			dp[i] += (dp[ch[y]]);
			dp[i] %= mod;
		}
		ch[a[i] - 'a'] = i;
	}
	for (int i = t; i < t + n; i++) {
		dp[i] = 1;
		int gap = 0;
		int cc = 0;
		for (int y = 0; y < m; y++) {
			if (i-ch[y]>gap) {
				gap=i-ch[y];
				cc = y;
			}
		}
		for (int y = 0; y < m; y++) {
			if (ch[y] == -1)continue;
			dp[i] += dp[ch[y]];
			dp[i] %= mod;
		}
		ch[cc] = i;
	}
	int dap = 1;
	for (int i = 0; i < m; i++) {
		if (ch[i] == -1)continue;
		dap += dp[ch[i]];
		dap %= mod;
	}
	printf("%d", dap);
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#define ll long long
#define mod 1000000007
using namespace std;
int n, m;
int nex[2000010][26];
int ch[26];
int dp[2000100];
string a,b;
int t;
int func(int here) {
	int &ret = dp[here];
	if (ret != -1)return ret;
	ret = 0;
	for (int i = 0; i < m; i++)
	{
		if (nex[here][i] == t)continue;
		ret += (func(nex[here][i]) + 1);
		ret %= mod;
	}
	return ret;
}
int main()
{
	memset(dp, -1, sizeof(dp));
	scanf("%d %d", &n, &m);
	cin >> a;
	b = " ";
	b += a;
	t = b.size();
	for (int i = 1; i < t; i++)
		ch[b[i] - 'a']=1;
	t += n;
	for (int i = 0; i < m; i++) {
		if (!ch[i]&&b.size()<t)b += 'a' + i;
	}
	while (1) {
		if (b.size() == t)break;
		for (int i = 0; i < m; i++) {
			if (b.size() < t)b += 'a' + i;
		}
	}
	for (int i = 0; i < m; i++)
		ch[i] = t;
	for (int i = t - 1; i >= 0; i--) {
		for (int y = 0; y < m; y++) {
			nex[i][y] = ch[y];
		}
		if (i)
			ch[b[i] - 'a'] = i;
	}
	printf("%d", (func(0)+1)%mod);
}


#include<iostream>
#include<string>
#include<algorithm>
#include<cstring>
#include<queue>
#define ll long long
#define mod 1000000007
using namespace std;
int n, m;
int nex[2000010][26];
int ch[26];
int dp[2000100];
string a,b;
int t;
int func(int here) {
	int &ret = dp[here];
	if (ret != -1)return ret;
	ret = 0;
	for (int i = 0; i < m; i++)
	{
		if (nex[here][i] == t)continue;
		ret += (func(nex[here][i]) + 1);
		ret %= mod;
	}
	return ret;
}
int main()
{
	memset(dp, -1, sizeof(dp));
	scanf("%d %d", &n, &m);
	cin >> a;
	b = " ";
	b += a;
	t = b.size();
	for (int i = 1; i < t; i++)
		ch[b[i] - 'a']++;
	t += n;
	priority_queue<pair<int, int>> qu;
	for (int i = 0; i < m; i++) {
		qu.push({ -ch[i],i });
	}
	while (1) {
		if (b.size() == t)break;
		int cst = -qu.top().first;
		int curr = qu.top().second;
		qu.pop();
		b += 'a' + curr;
		cst++;
		qu.push({ -cst,curr });
	}
	for (int i = 0; i < m; i++)
		ch[i] = t;
	for (int i = t - 1; i >= 0; i--) {
		for (int y = 0; y < m; y++) {
			nex[i][y] = ch[y];
		}
		if (i)
			ch[b[i] - 'a'] = i;
	}
	printf("%d", (func(0)+1)%mod);
}


#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:256000000")
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <bitset>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>

using namespace std;

typedef long long ll;
#define mp make_pair
#define pub push_back
#define XX first
#define YY second
#define db long double
#define all(a) a.begin(), a.end()
#define y1 dsfgsdfgsdfgsdfgsdfgsdfg
#define y0 asdfasdf3rcdt234d5c23xd234dx43
const int INF = (int)1e9 + 7;
const ll LINF = (ll)9e18 + 7;

const ll P1 = 353251;
const ll P2 = 239017;
const ll MOD = 1e9 + 7;
const ll MOD1 = 1e9 + 7;
const ll MOD2 = 1e9 + 9;

/*
const int MAX_MEM = 2e8;
int mpos = 0;
char mem[MAX_MEM];
void * operator new ( size_t n ) {
    char *res = mem + mpos;
    mpos += n;
    return (void *)res;
}
void operator delete ( void * ) { }
*/

int n, k;
string s;
ll dp[26];
ll ans = 1;
int uk[26];

const bool is_testing = 0;
int main() {
	srand('D' + 'E' + 'N' + 'I' + 'S' + 'S' + 'O' + 'N');
	//mt19937 rnd(time(NULL));
	//ios_base::sync_with_stdio(0); cin.tie(0);
	if (is_testing) {
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	} else {
		//freopen("ufo.in", "r", stdin);
		//freopen("ufo.out", "w", stdout);
	}
	for (int i = 0; i < 26; i++)
		uk[i] = -1;
	cin >> n >> k;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		ll last = ans;
		ans = ((ll)2 * ans - dp[s[i] - 'a'] + MOD) % MOD;
		dp[s[i] - 'a'] = last;
		uk[s[i] - 'a'] = i;
	}

	for (int i = 0; i < n; i++) {
		ll last = ans;
		int now = 0;
		for (int c = 0; c < k; c++) {
			if (uk[c] < uk[now])
				now = c;
		}
		ans = ((ll)2 * ans - dp[now] + MOD) % MOD;
		uk[now] = i + s.size();
		dp[now] = last;
	}

	cout << ans;
}


#include <bits/stdc++.h>
#define N 10000005
#define LL long long
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define mod 1000000007
using namespace std;
LL int n,son[N],t[N],tut[N],k,m,mn=INT_MAX,mnd;
char s[N];
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin>>m>>k;
	cin>>s+1;
    n=strlen(s+1);
    t[0]=1;
    t[n+1]=1;
    for(int i=1;i<=n;i++)
		tut[s[i]-'a']=i;
    for(int i=n+1;i<=n+m;i++)
    {
		mn=INT_MAX;
		for(int j=0;j<k;j++)
		{
			mn=min(tut[j],mn);
			if(mn==tut[j])
				mnd=j;
		}
		tut[mnd]=i;
		s[i]=mnd+'a';

	}

    for(int i=1;i<=n+m;i++)
    {
        t[i]=t[i-1]*2%mod;
        if(son[s[i]-'a']!=0)
            t[i]=((t[i]-t[son[s[i]-'a']-1])%mod +mod)%mod;
        son[s[i]-'a']=i;
	}
	cout<<(t[n+m]%mod);

}


#include <bits/stdc++.h>
#define N 1000005
#define LL long long
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define sp " "
#define endl "\n"
#define mod 1000000007
using namespace std;
LL int n,son[N],t[N],tut[N],k,m,mn=INT_MAX,mnd;
char s[N];
int main()
{
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(false);
	cin>>m>>k;
	cin>>s+1;
    n=strlen(s+1);
    t[0]=1;
    t[n+1]=1;
    for(int i=1;i<=n;i++)
		tut[s[i]-'a']=i;
    for(int i=n+1;i<=n+m;i++)
    {
		mn=INT_MAX;
		for(int j=0;j<k;j++)
		{
			mn=min(tut[j],mn);
			if(mn==tut[j])
				mnd=j;
		}
		tut[mnd]=i;
		s[i]=mnd+'a';

	}

    for(int i=1;i<=n+m;i++)
    {
        t[i]=t[i-1]*2%mod;
        if(son[s[i]-'a']!=0)
            t[i]=((t[i]-t[son[s[i]-'a']-1])%mod +mod)%mod;
        son[s[i]-'a']=i;
	}
	cout<<(t[n+m]%mod);

}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<iostream>
#include<cmath>
#include<queue>
#include<bitset>
#define ms(x,y) memset(x,y,sizeof x)
#define inf 0x3f3f3f3f
#define fir first
#define sec second
#define lb(x) (x&(-x))
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1010000;
int n,k,m;char s[maxn];
void add(int &a,int b){
	a+=b;if(a>=mod)a-=mod;
}
int now,dp[2][27],sum[2],ls[28];
int main(){
	scanf("%d%d%s",&n,&k,s+1);
	m=strlen(s+1);ls[27]=inf;
	for(int i=1;i<=m;i++){
		for(int j=0;j<k;j++){
			if(j==s[i]-'a')ls[j]=i,dp[now^1][j]=(sum[now]+1)%mod;
			else dp[now^1][j]=dp[now][j];
		}
		sum[now^1]=0;
		for(int j=0;j<k;j++)add(sum[now^1],dp[now^1][j]);
		//cout<<sum[now^1]<<endl;
		now^=1;
	}
	for(int i=1;i<=n;i++){
		int mn=27;
		for(int j=0;j<k;j++)if(ls[j]<ls[mn])mn=j;
		ls[mn]=i+m;
		for(int j=0;j<k;j++){
			if(j==mn)dp[now^1][j]=(sum[now]+1)%mod;
			else dp[now^1][j]=dp[now][j];
		}
		sum[now^1]=0;
		for(int j=0;j<k;j++)add(sum[now^1],dp[now^1][j]);
		//cout<<sum[now^1]<<endl;
		now^=1;
	}
	cout<<sum[now]+1<<endl;
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<string>
#include<iostream>
#include<cmath>
#include<queue>
#include<bitset>
#define ms(x,y) memset(x,y,sizeof x)
#define inf 0x3f3f3f3f
#define fir first
#define sec second
#define lb(x) (x&(-x))
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1010000;
int n,k,m;char s[maxn];
void add(int &a,int b){
	a+=b;if(a>=mod)a-=mod;
}
int now,dp[2][27],sum[2],ls[27];
int main(){
	scanf("%d%d%s",&n,&k,s+1);
	m=strlen(s+1);ls[0]=inf;
	for(int i=1;i<=m;i++){
		for(int j=0;j<k;j++){
			if(j==s[i]-'a')ls[j]=i,dp[now^1][j]=sum[now]+1;
			else dp[now^1][j]=dp[now][j];
		}
		sum[now^1]=0;
		for(int j=0;j<k;j++)add(sum[now^1],dp[now^1][j]);
		//cout<<sum[now^1]<<endl;
		now^=1;
	}
	for(int i=1;i<=n;i++){
		int mn=0;
		for(int j=0;j<k;j++)if(ls[j]<ls[mn])mn=j;
		ls[mn]=i+m;
		for(int j=0;j<k;j++){
			if(j==mn)dp[now^1][j]=sum[now]+1;
			else dp[now^1][j]=dp[now][j];
		}
		sum[now^1]=0;
		for(int j=0;j<k;j++)add(sum[now^1],dp[now^1][j]);
		//cout<<sum[now^1]<<endl;
		now^=1;
	}
	cout<<sum[now]+1<<endl;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back

const int maxn  = 2e6 + 10;
const ll mod = 1e9 + 7;

ll a[maxn], last[maxn], dp[30];

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  int n, k;
  cin >> n >> k;
  string t;
  cin >> t;
  int m = t.size();
  for(int i = 0; i < m; ++i) {
		a[i] = (int)(t[i] - 'a');
  }
  for(int i = 0; i < k; ++i) {
		last[i] = -1;
  }
  for(int i = 0; i < m; ++i) {
		last[a[i]] = i;
		ll ame = 1;
		for(int j = 0; j < k; ++j) {
			ame = (ame + dp[j]) % mod;
		}
		dp[a[i]] = ame;
  }
  last[85] = 1e9 + 1;
  for(int i = 0; i < n; ++i) {
		ll x = 85;
		for(int j = 0; j < k; ++j) {
			if(last[j] < last[x]) {
				x = j;
			}
		}
		last[x] = i + m;
		ll ame = 1;
		for(int j = 0; j < k; ++j) {
			ame = (ame + dp[j]) % mod;
		}
		dp[x] = ame;
  }
  ll res = 1;
  for(int i = 0; i < k; ++i) {
		res = (res + dp[i]) % mod;
  }
  cout << res << endl;
  return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=2e6+50;
const int mod=1e9+7;
using namespace std;
int n,m,k,i,j,l[26],t;
ll f[nmax],mn;
char s[nmax];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>k>>(s+1);
    m=strlen(s+1),f[0]=1;
    for(i=1;i<=m;i++)
	{
		f[i]=(f[i-1]*2)%mod;
		if(l[s[i]-'a'])f[i]=(f[i]-f[l[s[i]-'a']]+1+mod)%mod;
		l[s[i]-'a']=i;
	}
	for(;i<=m+n;i++)
	{
		f[i]=(f[i-1]*2)%mod;
		mn=llinf;
		for(j=0;j<k;j++)
		{
			if(!l[j])mn=0,t=j;
			else if(f[l[j]]<mn)mn=f[l[j]],t=j;
		}
		if(mn)mn--;
		f[i]=(f[i]-mn+mod)%mod;
		l[t]=i;
	}
	cout<<f[n+m]<<endl;
    return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=2e6+50;
const int mod=1e9+7;
using namespace std;
int n,m,k,i,j,l[26],t,mn;
ll f[nmax];
char s[nmax];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>k>>(s+1);
    m=strlen(s+1),f[0]=1;
    for(i=1;i<=m+n;i++)
	{
		f[i]=(f[i-1]*2)%mod;
		if(i<=m)t=s[i]-'a';
		else
		{
			mn=i;
			for(j=0;j<k;j++)if(l[j]<mn)mn=l[j],t=j;
		}
		if(l[t])f[i]=(f[i]-f[l[t]-1]+mod)%mod;
		l[t]=i;
	}
	cout<<f[n+m]<<endl;
    return 0;
}


#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define rc(x) return cout<<x<<endl,0
#define pb push_back
#define in insert
#define er erase
#define fd find
#define fr first
#define sc second
typedef long long ll;
const ll INF=0x3f3f3f3f3f3f3f3f;
const ll llinf=(1LL<<61);
const int inf=(1<<30);
const int nmax=2e6+50;
const int mod=1e9+7;
using namespace std;
int n,m,k,i,j,l[26],t;
ll f[nmax],mn;
char s[nmax];
int main()
{
	//freopen("sol.in","r",stdin);
	//freopen("sol.out","w",stdout);
	ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
    cin>>n>>k>>(s+1);
    m=strlen(s+1),f[0]=1;
    for(i=1;i<=m;i++)
	{
		f[i]=(f[i-1]*2)%mod;
		if(l[s[i]-'a'])f[i]=(f[i]-f[l[s[i]-'a']-1]+mod)%mod;
		l[s[i]-'a']=i;
	}
	for(;i<=m+n;i++)
	{
		f[i]=(f[i-1]*2)%mod;
		mn=llinf;
		for(j=0;j<k;j++)
		{
			if(!l[j])mn=0,t=j;
			else if(f[l[j]]<mn)mn=f[l[j]],t=j;
		}
		f[i]=(f[i]-f[l[t]-1]+mod)%mod;
		l[t]=i;
	}
	cout<<f[n+m]<<endl;
    return 0;
}


// new day,new strength,new thougts
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) int((c).size())
#define REP(i,n)  for(int i=0;i<int(n);i++)
#define REPD(i,n) for(int i=int(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);i++)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);i--)
#define all(s) (s).begin(),(s).end()
#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=2e5+10;
const ll mod=1e9+7;

#pragma GCC Optimize("Ofast")

ll lst[30];
ll dp=1;

int main(){
    ll n,k;cin>>n>>k;
    string s;cin>>s;

    REP(i,sz(s)){
	ll bf=dp;
	dp=(2*dp-lst[s[i]-'a']+mod)%mod;
	lst[s[i]-'a']=bf;
    }
    sort(lst,lst+k);

    REP(i,n){
	ll bf=dp;
	dp=(2*dp-lst[i%k]+mod)%mod;
	lst[i%k]=bf;
    }

    cout<<dp;
}


// new day,new strength,new thougts
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) int((c).size())
#define REP(i,n)  for(int i=0;i<int(n);i++)
#define REPD(i,n) for(int i=int(n)-1;i>=0;i--)
#define FOR(i,a,b) for(int i=int(a);i<=int(b);i++)
#define FORD(i,a,b) for(int i=int(a);i>=int(b);i--)
#define all(s) (s).begin(),(s).end()
#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=2e5+10;
const ll mod=1e9+7;

pll lst[30];
ll dp=1;

int main(){
    ll n,k;cin>>n>>k;
    string s;cin>>s;

    REP(i,sz(s)){
	ll bf=dp;
	dp=(2*dp-lst[s[i]-'a'].S+mod)%mod;
	lst[s[i]-'a'].S=bf;
	lst[s[i]-'a'].F=i+1;
    }
    sort(lst,lst+k);

    REP(i,n){
	ll bf=dp;
	dp=(2*dp-lst[i%k].S+mod)%mod;
	lst[i%k].S=bf;
    }

    cout<<dp;
}


#include<bits/stdc++.h>
#define MOD 1000000007
using namespace std;

long long int dp[2000007],sum[2000007];
int main()
{
    long long int n,k,i,l;
    int last[27];
    string s;
    vector<pair<int,char> > v;

    cin>>n>>k;

    cin>>s;

    for(i=0;i<k;i++)
        v.push_back(make_pair(-1,'a'+i));

    for(i=0;i<s.length();i++)
        v[s[i]-'a'].first=i;

    sort(v.begin(),v.end());

    l=0;
    for(i=0;i<n;i++)
    {
        s+=v[l].second;
        l++;
        if(l==k)
            l=0;
    }

    memset(last,-1,sizeof(last));
    dp[0]=1;

    sum[0]=1;
    for(i=0;i<s.length();i++)
    {
        dp[i+1]=dp[i]*2;
        if(last[s[i]-'a']!=-1)
            dp[i+1]=(dp[i+1]-dp[last[s[i]-'a']]);

        dp[i+1]=(dp[i+1]%MOD+MOD)%MOD;
        last[s[i]-'a']=i;

    }

    cout<<dp[s.length()];

    return 0;

}


///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           meme(x)                     memset(x,0,sizeof(x));
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=2000009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int dp[28];
int last[28];

 main()

{
    fast
    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int sz=s.size();
    f(i,0,sz-1)
    {
        int c=s[i]-'a';
        int sum=1LL;
        f(k,0,25)
        {
            sum=(sum+dp[k])%mod;
        }
        dp[c]=sum;
        last[c]=i+1;
    }
    f(i,1,n)
    {
        int c,sum=1LL,mn=inf;
        f(k,0,25)
        {
            if(last[k]<mn)
            {
                mn=last[k];
                c=k;
            }
            sum=(sum+dp[k])%mod;
        }
        dp[c]=sum;
        last[c]=sz+i+2;
    }
    int ses=1LL;
    f(k,0,25)ses=(ses+dp[k])%mod;
    cout<<ses<<endl;
    return 0;

}


///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           meme(x)                     memset(x,0,sizeof(x));
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=2000009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int dp[28];
int last[28];

 main()

{
    fast
    int n,lim;
    cin>>n>>lim;lim--;
    string s;
    cin>>s;
    int sz=s.size();
    f(i,0,sz-1)
    {
        int c=s[i]-'a';
        int sum=1LL;
        f(k,0,lim)
        {
            sum=(sum+dp[k])%mod;
        }
        dp[c]=sum;
        last[c]=i+1;
    }
    f(i,1,n)
    {
        int c,sum=1LL,mn=inf;
        f(k,0,lim)
        {
            if(last[k]<mn)
            {
                mn=last[k];
                c=k;
            }
            sum=(sum+dp[k])%mod;
        }
        dp[c]=sum;
        last[c]=sz+i;
    }
    int ses=1LL;
    f(k,0,lim)ses=(ses+dp[k])%mod;
    cout<<ses<<endl;
    return 0;

}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int n,m,k;
int last[30];
int pos[30];
char s[1000005];
main()
{
    int i,x,y,t,sum;
    scanf("%d%d %s",&n,&k,s);
    m = strlen(s);
    memset(pos,-1,sizeof(pos));
    sum = 1;
    for(i=0;i<m;i++)
    {
        x = s[i]-'a';
        t = sum - last[x];
        last[x] = sum;
        pos[x] = i;
        sum = (sum + t)%mod;
    }
    for(i=m;i<m+n;i++)
    {
        y = -1;
        for(x=0;x<k;x++) if(y==-1 || pos[y]>pos[x]) y = x;
        t = sum - last[y];
        last[y] = sum;
        pos[y] = i;
        sum = (sum + t)%mod;
    }
    printf("%d",sum);
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int n,m,k;
int last[30];
char s[1000005];
main()
{
    int i,x,y,t,sum;
    scanf("%d%d %s",&n,&k,s);
    m = strlen(s);
    sum = 1;
    for(i=0;i<m;i++)
    {
        x = s[i]-'a';
        t = sum - last[x];
        last[x] = sum;
        sum = (sum + t)%mod;
    }
    for(i=0;i<n;i++)
    {
        y = -1;
        for(x=0;x<k;x++) if(y==-1 || last[y]>last[x]) y = x;
        t = sum - last[y];
        last[y] = sum;
        sum = (sum + t)%mod;
    }
    printf("%d",sum);
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int n,m,k;
int last[30];
int pos[30];
char s[1000005];
main()
{
    int i,x,y,t,sum;
    scanf("%d%d %s",&n,&k,s);
    m = strlen(s);
    sum = 1;
    for(i=0;i<m;i++)
    {
        x = s[i]-'a';
        t = sum - last[x];
        last[x] = sum;
        pos[x] = i;
        sum = (sum + t)%mod;
    }
    for(i=m;i<m+n;i++)
    {
        y = -1;
        for(x=0;x<k;x++) if(y==-1 || pos[y]>pos[x]) y = x;
        t = sum - last[y];
        last[y] = sum;
        pos[y] = i;
        sum = (sum + t)%mod;
    }
    printf("%d",sum);
}


#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007
int n,m,k;
int last[30];
int pos[30];
char s[1000005];
main()
{
    int i,x,y,t,sum;
    scanf("%d%d %s",&n,&k,s);
    m = strlen(s);
    memset(pos,-1,sizeof(pos));
    sum = 1;
    for(i=0;i<m;i++)
    {
        x = s[i]-'a';
        t = sum - last[x];
        last[x] = sum;
        pos[x] = i;
        sum = ((sum + t)%mod + mod)%mod;
    }
    for(i=m;i<m+n;i++)
    {
        y = -1;
        for(x=0;x<k;x++) if(y==-1 || pos[y]>pos[x]) y = x;
        t = sum - last[y];
        last[y] = sum;
        pos[y] = i;
        sum = ((sum + t)%mod + mod)%mod;
    }
    printf("%d",sum);
}


#include <bits/stdc++.h>

#define task "E"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int mod = 1e9 + 7;
int n, K, dp[26];
string s;
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> K >> s;
    int sum = 1;

    rep(i, 0, SZ(s) - 1)
    {
        int lst = dp[s[i] - 'a'];
        dp[s[i] - 'a'] = sum;
        (sum += (sum - lst + mod) % mod) %= mod;
    }
    priority_queue<ii, vii, greater<ii> > pq;
    rep(j, 0, K - 1) pq.push({dp[j], j});
    rep(i, 1, n)
    {

        ii it = pq.top();
        pq.pop();
        dp[it.S] = sum;
        (sum += (sum - it.F + mod) % mod) %= mod;
        pq.push({dp[it.S], it.S});
    }
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>

#define task "E"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (ll i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const ll mod = 1e9 + 7;
ll n, K, dp[26];
string s;
bool in[26];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> K >> s;
    ll sum = 1;

    rep(i, 0, SZ(s) - 1)
    {
        ll lst = dp[s[i] - 'a'];
        dp[s[i] - 'a'] = sum;
        (sum += (sum - lst + mod) % mod) %= mod;
    }
    deque<int> dq;
    Rep(i, SZ(s) - 1, 0) if (!in[s[i] - 'a'])
    {
        in[s[i] - 'a'] = 1;
        dq.pf(s[i] - 'a');
    }
    rep(i, 0, 25) if (!in[i]) dq.pf(i);
    rep(i, 1, n)
    {
        int id = dq.front();
        dq.pop_front();
        dq.pb(id);
        int lst = dp[id];
        dp[id] = sum;
        (sum += (sum - lst + mod) % mod) %= mod;
    }
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>

#define task "E"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (ll i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const ll mod = 1e9 + 7;
ll n, K, dp[26];
string s;
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> K >> s;
    ll sum = 1;

    rep(i, 0, SZ(s) - 1)
    {
        ll lst = dp[s[i] - 'a'];
        dp[s[i] - 'a'] = sum;
        (sum += (sum - lst + mod) % mod) %= mod;
    }
    priority_queue<ii, vii, greater<ii> > pq;
    rep(j, 0, K - 1) pq.push({dp[j], j});
    rep(i, 1, n)
    {
        ii it = pq.top();
        pq.pop();
        dp[it.S] = sum;
        (sum += (sum - it.F + mod) % mod) %= mod;
        pq.push({dp[it.S], it.S});
    }
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>

#define task "E"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (ll i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (ll i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((ll)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<ll, ll> ii;
typedef pair<ii, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const ll mod = 1e9 + 7;
ll n, K, dp[26];
string s;
bool in[26];
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n >> K >> s;
    ll sum = 1;

    rep(i, 0, SZ(s) - 1)
    {
        ll lst = dp[s[i] - 'a'];
        dp[s[i] - 'a'] = sum;
        (sum += (sum - lst + mod) % mod) %= mod;
    }
    deque<int> dq;
    Rep(i, SZ(s) - 1, 0) if (!in[s[i] - 'a'])
    {
        in[s[i] - 'a'] = 1;
        dq.pf(s[i] - 'a');
    }
    rep(i, 0, K - 1) if (!in[i]) dq.pf(i);
    rep(i, 1, n)
    {
        int id = dq.front();
        dq.pop_front();
        dq.pb(id);
        int lst = dp[id];
        dp[id] = sum;
        (sum += (sum - lst + mod) % mod) %= mod;
    }
    cout << sum;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int mx = 2e6+1, mod = 1e9+7;

int n, m, k, ts, ms;

string s;

int last[mx];

vector<pii> t;

int nxt[mx][27];

int dp[mx];

main()
{
    cin >> n >> k >> s;

    for(int i=1;i<=s.size();i++)
        last[s[i-1]]=i;

    for(int i='a';i<k+'a';i++)
        t.push_back(mp(last[i], i));
    ts = t.size();

    sort(t.begin(), t.end());

    for(int i=0;i<n;i++)
        s+=(char)t[i%ts].ss;

    ms = s.size();

    for(int l='a';l<k+'a';l++)
    {
        int nx=ms;
        for(int i=ms-1;i>=0;i--)
        {
            nxt[i][l-'a']=nx;
            if(s[i]==l)
                nx=i;
        }
        dp[nx]=1;
    }

    int ans=1;

    for(int i=0;i<ms;i++)
        for(int l='a';l<k+'a';l++)
            if(nxt[i][l-'a']!=ms)
                dp[nxt[i][l-'a']]=(0LL+dp[nxt[i][l-'a']]+dp[i])%mod;

    for(int i=0;i<ms;i++)
        ans=(0LL+ans+dp[i])%mod;

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int mx = 1e6+15, mod = 1e9+7;

int n, m, k, ts, ms;

string s;

int last[mx];

vector<pii> t;

int nxt[mx][26];

vector<int> e[mx];

int dp[mx];

main()
{
    cin >> n >> k >> s;

    for(int i=1;i<=s.size();i++)
        last[s[i-1]]=i;

    for(int i='a';i<k+'a';i++)
        t.push_back(mp(last[i], i));
    ts = t.size();

    sort(t.begin(), t.end());

    for(int i=0;i<n;i++)
        s+=(char)t[i%ts].ss;

    ms = s.size();

    for(int l='a';l<k+'a';l++)
    {
        int nx=ms;
        for(int i=ms-1;i>=0;i--)
        {
            nxt[i][l-'a']=nx;
            if(s[i]==l)
                nx=i;
        }
        dp[nx]=1;
    }

    for(int l='a';l<k+'a';l++)
        for(int i=0;i<ms;i++)
            if(nxt[i][l-'a']!=ms)
                e[i].pb(nxt[i][l-'a']);

    int ans=1;

    for(int i=0;i<ms;i++)
        for(int j=0;j<e[i].size();j++)
            dp[e[i][j]]=(dp[e[i][j]]+dp[i])%mod;

    for(int i=0;i<ms;i++)
        ans=(ans+dp[i])%mod;

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int mx = 1e6+1, mod = 1e9+7;

int n, m, k, ts, ms;

string s;

int last[mx];

vector<pii> t;

int nxt[mx][27];

int dp[mx];

main()
{
    cin >> n >> k >> s;

    for(int i=1;i<=s.size();i++)
        last[s[i-1]]=i;

    for(int i='a';i<k+'a';i++)
        t.push_back(mp(last[i], i));
    ts = t.size();

    sort(t.begin(), t.end());

    for(int i=0;i<n;i++)
        s+=(char)t[i%ts].ss;

    ms = s.size();

    for(int l='a';l<k+'a';l++)
    {
        int nx=ms;
        for(int i=ms-1;i>=0;i--)
        {
            nxt[i][l-'a']=nx;
            if(s[i]==l)
                nx=i;
        }
        dp[nx]=1;
    }

    int ans=1;

    for(int i=0;i<ms;i++)
        for(int l='a';l<k+'a';l++)
            if(nxt[i][l-'a']!=ms)
                dp[nxt[i][l-'a']]=(dp[nxt[i][l-'a']]+dp[i])%mod;

    for(int i=0;i<ms;i++)
        ans=(ans+dp[i])%mod;

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int mx = 1e6+15, mod = 1e9+7;

int n, m, k, ts, ms;

string s;

int last[mx];

vector<pii> t;

int next[mx]['z'+1];

vector<int> e[mx];

int dp[mx];

main()
{
    cin >> n >> k >> s;

    for(int i=1;i<=s.size();i++)
        last[s[i-1]]=i;

    for(char i='a';i<k+'a';i++)
        t.push_back(mp(last[i], i));
    ts = t.size();

    sort(t.begin(), t.end());

    for(int i=0;i<n;i++)
        s+=(char)t[i%ts].ss;

    ms = s.size();

    for(char l='a';l<k+'a';l++)
    {
        int nx=ms;
        for(int i=ms-1;i>=0;i--)
        {
            next[i][l]=nx;
            if(s[i]==l)
                nx=i;
        }
        dp[nx]=1;
    }

    for(char l='a';l<k+'a';l++)
        for(int i=0;i<ms;i++)
            if(next[i][l]!=ms)
                e[i].pb(next[i][l]);

    int ans=1;

    for(int i=0;i<ms;i++)
        for(int j=0;j<e[i].size();j++)
            dp[e[i][j]]=(dp[e[i][j]]+dp[i])%mod;

    for(int i=0;i<ms;i++)
        ans=(ans+dp[i])%mod;

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int mx = 1e6+15, mod = 1e9+7;

int n, m, k, ts, ms;

string s;

int last[mx];

vector<pii> t;

int next[mx][26];

vector<int> e[mx];

int dp[mx];

main()
{
    cin >> n >> k >> s;

    for(int i=1;i<=s.size();i++)
        last[s[i-1]]=i;

    for(int i='a';i<k+'a';i++)
        t.push_back(mp(last[i], i));
    ts = t.size();

    sort(t.begin(), t.end());

    for(int i=0;i<n;i++)
        s+=(char)t[i%ts].ss;

    ms = s.size();

    for(int l='a';l<k+'a';l++)
    {
        int nx=ms;
        for(int i=ms-1;i>=0;i--)
        {
            next[i][l-'a']=nx;
            if(s[i]==l)
                nx=i;
        }
        dp[nx]=1;
    }

    for(int l='a';l<k+'a';l++)
        for(int i=0;i<ms;i++)
            if(next[i][l-'a']!=ms)
                e[i].pb(next[i][l-'a']);

    int ans=1;

    for(int i=0;i<ms;i++)
        for(int j=0;j<e[i].size();j++)
            dp[e[i][j]]=(dp[e[i][j]]+dp[i])%mod;

    for(int i=0;i<ms;i++)
        ans=(ans+dp[i])%mod;

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int mx = 1e6+20, mod = 1e9+7;

int n, m, k, ts, ms;

string s;

int last[mx];

vector<pii> t;

int nxt[mx][30];

vector<int> e[mx];

int dp[mx];

main()
{
    cin >> n >> k >> s;

    for(int i=1;i<=s.size();i++)
        last[s[i-1]]=i;

    for(int i='a';i<k+'a';i++)
        t.push_back(mp(last[i], i));
    ts = t.size();

    sort(t.begin(), t.end());

    for(int i=0;i<n;i++)
        s+=(char)t[i%ts].ss;

    ms = s.size();

    for(int l='a';l<k+'a';l++)
    {
        int nx=ms;
        for(int i=ms-1;i>=0;i--)
        {
            nxt[i][l-'a']=nx;
            if(s[i]==l)
                nx=i;
        }
        dp[nx]=1;
    }

    int ans=1;

    for(int i=0;i<ms;i++)
        for(int l='a';l<k+'a';l++)
            if(nxt[i][l-'a']!=ms)
                dp[nxt[i][l-'a']]=(dp[nxt[i][l-'a']]+dp[i])%mod;

    for(int i=0;i<ms;i++)
        ans=(ans+dp[i])%mod;

    cout << ans;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

#define int long long int
#define pii pair<int,int>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back

const int mx = 1e6+15, mod = 1e9+7;

int n, m, k, ts, ms;

string s;

int last[mx];

vector<pii> t;

int next['z'+1][mx];

vector<int> e[mx];

int dp[mx];

main()
{
    cin >> n >> k >> s;

    for(int i=1;i<=s.size();i++)
        last[s[i-1]]=i;

    for(char i='a';i<k+'a';i++)
        t.push_back(mp(last[i], i));
    ts = t.size();

    sort(t.begin(), t.end());

    for(int i=0;i<n;i++)
        s+=(char)t[i%ts].ss;

    ms = s.size();

    for(char l='a';l<k+'a';l++)
    {
        int nx=ms;
        for(int i=ms-1;i>=0;i--)
        {
            next[i][l]=nx;
            if(s[i]==l)
                nx=i;
        }
        dp[nx]=1;
    }

    for(char l='a';l<k+'a';l++)
        for(int i=0;i<ms;i++)
            if(next[i][l]!=ms)
                e[i].pb(next[i][l]);

    int ans=1;

    for(int i=0;i<ms;i++)
        for(int j=0;j<e[i].size();j++)
            dp[e[i][j]]=(dp[e[i][j]]+dp[i])%mod;

    for(int i=0;i<ms;i++)
        ans=(ans+dp[i])%mod;

    cout << ans;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+105,K=105,mod=1e9+7;
int n,k,m,a[N],pre[K],f[N],p[N],pw[K];
char ch[N];
struct cmp{bool operator()(const int&x,const int&y){return pre[x]<pre[y];}};
inline int add(int x,int y){x+=y;return x>=mod?x-mod:x;}
inline int dec(int x,int y){x-=y;return x<0?x+mod:x;}
inline int mul(int x,int y){return 1ll*x*y%mod;}
inline void work(int l,int r)
{
	for(int i=l;i<=r;++i)
	{
		f[i]=add(f[i-1],f[i-1]);
		f[i]=pre[a[i]]?dec(f[i],f[pre[a[i]]-1]):add(f[i],1);
		pre[a[i]]=i;
	}
}
struct Matrix
{
	int c[K][K];
	inline void pre(int d=0)
	{
		memset(c,0,sizeof(c));
		for(int i=1;i<=k+1;++i)c[i][i]=d;
	}
	Matrix operator*(const Matrix&rhs)
	{
		Matrix z;z.pre();
		for(int i=1;i<=k+1;++i)
			for(int j=1;j<=k+1;++j)
				for(int l=1;l<=k+1;++l)
					z.c[i][j]=add(z.c[i][j],mul(c[i][l],rhs.c[l][j]));
		return z;
	}
};
Matrix operator^(Matrix&x,ll y)
{
	Matrix ans;ans.pre(1);
	for(;y;y>>=1,x=x*x)
		if(y&1)ans=ans*x;
	return ans;
}
int main()
{
	scanf("%d%d",&n,&k);scanf("%s",ch+1);m=strlen(ch+1);swap(n,m);
	for(int i=1;i<=n;++i)a[i]=ch[i]-'a'+1;
	work(1,n);
	for(int i=1;i<=k;++i)p[i]=i;
	sort(p+1,p+k+1,cmp());
	for(int i=n+1;i<=n+k;++i)a[i]=p[i-n];
	work(n+1,n+k);
	if(m<=k){printf("%d\n",f[n+m]+1);return 0;}
	pw[0]=1;for(int i=1;i<=k;++i)pw[i]=add(pw[i-1],pw[i-1]);
	Matrix mat;mat.pre();
	for(int i=2;i<=k+1;++i)mat.c[i][i-1]=dec(mat.c[i][i-1],1);
	for(int i=1;i<=k+1;++i)mat.c[i][k+1]=add(mat.c[i][k+1],pw[i-1]);
	for(int i=3;i<=k+1;++i)
		for(int j=1;j<=i-2;++j)
			mat.c[i][j]=dec(mat.c[i][j],pw[i-j-1]);
	int c=(m-1)/k;m-=c*k;mat=mat^c;
	int ans=0;
	for(int i=0;i<=k;++i)ans=add(ans,mul(f[n+i],mat.c[m+1][i+1]));
	printf("%d\n",ans+1);
	return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
}

const int maxn=2000010;
char s[maxn],t[maxn];
int n,k,pre[maxn];
bool f[maxn],g[maxn];
LL dp[maxn],mod=1e9+7;

int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",t); int m=strlen(t);
    for(int i=1;i<=m;i++)
    {
        dp[i]=2*dp[i-1]%mod;
        if(pre[t[i-1]]!=0) dp[i]=(dp[i]-dp[pre[t[i-1]]-1]+mod)%mod;
        if(!f[t[i-1]]) f[t[i-1]]=1, dp[i]=(dp[i]+1)%mod;
        pre[t[i-1]]=i;
    }
    //for(int i=1;i<=m;i++) cout<<dp[i]<<" ";

    for(int i=0;i<m;i++) g[t[i]-'a']=i+1;

    for(int i=m+1;i<=m+n;i++)
    {
        int mi=30,num=3000000;
        for(int i=0;i<k;i++) if(g[i]<num) num=g[i],mi=i;

        t[i-1]=mi+'a';
        dp[i]=2*dp[i-1]%mod;
        if(pre[t[i-1]]!=0) dp[i]=(dp[i]-dp[pre[t[i-1]]-1]+mod)%mod;
        if(!f[t[i-1]]) f[t[i-1]]=1, dp[i]=(dp[i]+1)%mod;
        pre[t[i-1]]=i; g[t[i-1]-'a']=i;
    }
    printf("%lld\n",(dp[m+n]+1)%mod);

    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
}

const int maxn=2000010;
char s[maxn],t[maxn];
int n,k,pre[maxn];
bool f[maxn],g[maxn];
LL dp[maxn],mod=1e9+7;

int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",t); int m=strlen(t);
    for(int i=1;i<=m;i++)
    {
        dp[i]=2*dp[i-1]%mod;
        if(pre[t[i-1]]!=0) dp[i]=(dp[i]-dp[pre[t[i-1]]-1]+mod)%mod;
        if(!f[t[i-1]]) f[t[i-1]]=1, dp[i]=(dp[i]+1)%mod;
        pre[t[i-1]]=i;
    }
    //for(int i=1;i<=m;i++) cout<<dp[i]<<" ";

    for(int i=0;i<m;i++) g[t[i]-'a']=i+1;

    for(int i=m+1;i<=m+n;i++)
    {
        int mi=30,num=3000000;
        for(int j=0;j<k;j++) if(g[j]<num) num=g[j],mi=j;

        t[i-1]=mi+'a';
        dp[i]=2*dp[i-1]%mod;
        if(pre[t[i-1]]!=0) dp[i]=(dp[i]-dp[pre[t[i-1]]-1]+mod)%mod;
        if(!f[t[i-1]]) f[t[i-1]]=1, dp[i]=(dp[i]+1)%mod;
        pre[t[i-1]]=i; g[t[i-1]-'a']=i;
    }
    printf("%lld\n",(dp[m+n]+1)%mod);

    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
}

const int maxn=2000010;
char s[maxn],t[maxn];
int n,k,pre[maxn];
bool f[maxn];int g[maxn];
LL dp[maxn],mod=1e9+7;

int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",t); int m=strlen(t);
    for(int i=1;i<=m;i++)
    {
        dp[i]=2*dp[i-1]%mod;
        if(pre[t[i-1]]!=0) dp[i]=(dp[i]-dp[pre[t[i-1]]-1]+mod)%mod;
        if(!f[t[i-1]]) f[t[i-1]]=1, dp[i]=(dp[i]+1)%mod;
        pre[t[i-1]]=i;
    }
    //for(int i=1;i<=m;i++) cout<<dp[i]<<" ";

    for(int i=0;i<m;i++) g[t[i]-'a']=i+1;

    for(int i=m+1;i<=m+n;i++)
    {
        int mi=30,num=3000000;
        for(int j=0;j<k;j++) if(g[j]<num) num=g[j],mi=j;

        t[i-1]=mi+'a';
        dp[i]=2*dp[i-1]%mod;
        if(pre[t[i-1]]!=0) dp[i]=(dp[i]-dp[pre[t[i-1]]-1]+mod)%mod;
        if(!f[t[i-1]]) f[t[i-1]]=1, dp[i]=(dp[i]+1)%mod;
        pre[t[i-1]]=i; g[t[i-1]-'a']=i;
    }
    printf("%lld\n",(dp[m+n]+1)%mod);

    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
}

const int maxn=2000010;
char s[maxn],t[maxn];
int n,k,pre[maxn];
bool f[maxn],g[maxn];
LL dp[maxn],mod=1e9+7;

int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",t); int m=strlen(t);
    for(int i=1;i<=m;i++)
    {
        dp[i]=2*dp[i-1]%mod;
        if(pre[t[i-1]]!=0) dp[i]=(dp[i]-dp[pre[t[i-1]]-1]+mod)%mod;
        if(!f[t[i-1]]) f[t[i-1]]=1, dp[i]=(dp[i]+1)%mod;
        pre[t[i-1]]=i;
    }
    //for(int i=1;i<=m;i++) cout<<dp[i]<<" ";

    for(int i=0;i<m;i++) g[t[i]-'a']=i+1;

    for(int i=m+1;i<=m+n;i++)
    {
        int mi=30,num=3000000;
        for(int i=0;i<26;i++) if(g[i]<num) num=g[i],mi=i;

        t[i-1]=mi+'a';
        dp[i]=2*dp[i-1]%mod;
        if(pre[t[i-1]]!=0) dp[i]=(dp[i]-dp[pre[t[i-1]]-1]+mod)%mod;
        if(!f[t[i-1]]) f[t[i-1]]=1, dp[i]=(dp[i]+1)%mod;
        pre[t[i-1]]=i; g[t[i-1]-'a']=i;
    }
    printf("%lld\n",(dp[m+n]+1)%mod);

    return 0;
}


#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<bitset>
#include<iostream>
using namespace std;
typedef long long LL;
const double pi=acos(-1.0),eps=1e-6;
void File()
{
    freopen("D:\\in.txt","r",stdin);
    freopen("D:\\out.txt","w",stdout);
}
template <class T>
inline void read(T &x)
{
    char c=getchar(); x=0;
    while(!isdigit(c)) c=getchar();
    while(isdigit(c)) {x=x*10+c-'0'; c=getchar();}
}

const int maxn=1000010;
int n,k,pre[maxn];
LL f[30],mod=1e9+7;
char s[maxn];

int main()
{
    scanf("%d%d",&n,&k);
    scanf("%s",s); int m=strlen(s);
    for(int i=1;i<=m;i++)
    {
        LL sum=0; for(int j=1;j<=k;j++) sum=(sum+f[j])%mod;
        f[s[i-1]-'a'+1]=(sum+1)%mod; pre[s[i-1]-'a'+1]=i;
    }

    for(int i=m+1;i<=m+n;i++)
    {
        LL sum=0; for(int j=1;j<=k;j++) sum=(sum+f[j])%mod;
        int mx=3*maxn,mi;
        for(int j=1;j<=k;j++) if(pre[j]<mx) mi=j,mx=pre[j];
        f[mi]=(sum+1)%mod; pre[mi]=i;
    }

    LL ans=0;
    for(int i=1;i<=k;i++) ans=(ans+f[i])%mod;
    printf("%lld\n",(ans+1)%mod);

    return 0;
}


#include<bits/stdc++.h>
typedef long long int ll;
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll added,charno;
    string str;
    cin>>added>>charno>>str;
    ll len=str.size();
    ll dp[charno];
    ll freq[charno];
    for(int i=0;i<charno;i++)
    {
        dp[i]=0;
        freq[i]=0;
    }
    ll charidx;
    for(int i=0;i<len;i++)
    {
        charidx=str[i]-'a';
        freq[charidx]++;
        for(int j=0;j<charno;j++)
        {
            if(j==charidx)
            {
                continue;
            }
            dp[charidx]+=dp[j];
            if(dp[charidx]>=MOD)
            {
                dp[charidx]-=MOD;
            }
        }
        dp[charidx]++;
    }
    queue<ll> q1;
    for(int i=0;i<charno;i++)
    {
        if(freq[i]==0)
        {
            q1.push(i);
        }
        freq[i]=0;
    }
    for(int i=len-1;i>=0;i--)
    {
        charidx=str[i]-'a';
        if(freq[charidx]==0)
        {
            freq[charidx]++;
            q1.push(charidx);
        }
    }
    while(added--)
    {
        charidx=q1.front();
        q1.pop();
        q1.push(charidx);
        for(int j=0;j<charno;j++)
        {
            if(j==charidx)
            {
                continue;
            }
            dp[charidx]+=dp[j];
            if(dp[charidx]>=MOD)
            {
                dp[charidx]-=MOD;
            }
        }
        dp[charidx]++;
    }
    ll ans=0;
    for(ll i=0;i<charno;i++)
    {
        ans=(ans+dp[i])%MOD;
    }
    ans++;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
typedef long long int ll;
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll>
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll added,charno;
    string str;
    cin>>added>>charno>>str;
    ll len=str.size();
    ll dp[charno];
    ll freq[charno];
    for(int i=0;i<charno;i++)
    {
        dp[i]=0;
        freq[i]=0;
    }
    ll charidx;
    for(int i=0;i<len;i++)
    {
        charidx=str[i]-'a';
        freq[charidx]++;
        for(int j=0;j<charno;j++)
        {
            if(j==charidx)
            {
                continue;
            }
            dp[charidx]+=dp[j];
            if(dp[charidx]>=MOD)
            {
                dp[charidx]-=MOD;
            }
        }
        dp[charidx]++;
    }
    queue<ll> q1;
    for(int i=0;i<charno;i++)
    {
        if(freq[i]==0)
        {
            q1.push(i);
        }
        freq[i]=0;
    }
    stack <ll>s1 ;
    for(int i=len-1;i>=0;i--)
    {
        charidx=str[i]-'a';
        if(freq[charidx]==0)
        {
            freq[charidx]++;
            s1.push(charidx);
        }
    }
    while(!s1.empty())
    {
        q1.push(s1.top());
        s1.pop();
    }
    while(added--)
    {
        charidx=q1.front();
        q1.pop();
        q1.push(charidx);
        for(int j=0;j<charno;j++)
        {
            if(j==charidx)
            {
                continue;
            }
            dp[charidx]+=dp[j];
            if(dp[charidx]>=MOD)
            {
                dp[charidx]-=MOD;
            }
        }
        dp[charidx]++;
    }
    ll ans=0;
    for(ll i=0;i<charno;i++)
    {
        ans=(ans+dp[i])%MOD;
    }
    ans++;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<random>
using namespace std;

#define MAX 2000002

#define MM 27
int let[MM];

char buf[MAX];

int n;
int k;

string s;

vector<pair<int, int> > v;

#define MOD 1000000007
long long int im[MAX];

int main(){
	memset(let, -1, sizeof(let));
	cin >> n >> k;
	scanf("%s", buf);
	s = buf;
	for (int i = 0; i < s.size(); i++){
		let[s[i] - 'a'] = i;
	}
	for (int i = 0; i < k; i++){
		v.push_back(make_pair(let[i], i));
	}
	sort(v.begin(), v.end());
	while (n){
		for (int i = 0; i < v.size()&&n; i++){
			s.push_back(v[i].second + 'a');
			n--;
		}
	}
	memset(let, -1, sizeof(let));
	for (int i = 0; i < s.size(); i++){
		int v = s[i] - 'a';
		int rig = let[v];
		rig = max(rig, 0);
		long long int D = 0;
		if (i){
			D += im[i - 1];
		}
		if (rig){
			D += MOD-im[rig - 1];
		}
		if (D >= MOD)D %= MOD;
		if (let[v] == -1){
			D++;
		}
		im[i] = D;
		if (i){
			im[i] += im[i - 1];
		}
		if (im[i] >= MOD)im[i] %= MOD;
		let[v] = i;
	}
	im[s.size() - 1]++;
	im[s.size() - 1] %= MOD;
	printf("%lld\n", im[s.size() - 1]);
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<random>
using namespace std;

#define MAX 2000002

#define MM 27
int let[MM];

char buf[MAX];

int n;
int k;

string s;

vector<pair<int, int> > v;

#define MOD 1000000007
long long int im[MAX];

int main(){
	memset(let, -1, sizeof(let));
	cin >> n >> k;
	scanf("%s", buf);
	s = buf;
	for (int i = 0; i < s.size(); i++){
		let[s[i] - 'a'] = i;
	}
	for (int i = 0; i < k; i++){
		v.push_back(make_pair(let[i], i));
	}
	sort(v.begin(), v.end());
	while (n){
		for (int i = 0; i < v.size()&&n; i++){
			s.push_back(v[i].second + 'a');
			n--;
		}
	}
	memset(let, -1, sizeof(let));
	for (int i = 0; i < s.size(); i++){
		int v = s[i] - 'a';
		int rig = let[v];
		rig = max(rig, 0);
		long long int D = 0;
		if (i){
			D += im[i - 1];
		}
		if (rig){
			D -= im[rig - 1];
		}
		if (let[v] == -1){
			D++;
		}
		im[i] = D;
		if (i){
			im[i] += im[i - 1];
		}
		if (im[i] >= MOD)im[i] %= MOD;
		let[v] = i;
	}
	im[s.size() - 1]++;
	im[s.size() - 1] %= MOD;
	printf("%lld\n", im[s.size() - 1]);
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<random>
using namespace std;

#define MAX 1000002

#define MM 27
int let[MM];

char buf[MAX];

int n;
int k;

string s;

vector<pair<int, int> > v;

#define MOD 1000000007
long long int im[MAX];

int main(){
	memset(let, -1, sizeof(let));
	cin >> n >> k;
	scanf("%s", buf);
	s = buf;
	for (int i = 0; i < s.size(); i++){
		let[s[i] - 'a'] = i;
	}
	for (int i = 0; i < 26; i++){
		v.push_back(make_pair(let[i], i));
	}
	sort(v.begin(), v.end());
	while (n){
		for (int i = 0; i < v.size()&&n; i++){
			s.push_back(v[i].second + 'a');
			n--;
		}
	}
	memset(let, -1, sizeof(let));
	for (int i = 0; i < s.size(); i++){
		int v = s[i] - 'a';
		int rig = let[v];
		rig = max(rig, 0);
		long long int D = 0;
		if (i){
			D += im[i - 1];
		}
		if (rig){
			D -= im[rig - 1];
		}
		if (let[v] == -1){
			D++;
		}
		im[i] = D;
		if (i){
			im[i] += im[i - 1];
		}
		if (im[i] >= MOD)im[i] %= MOD;
		let[v] = i;
	}
	im[s.size() - 1]++;
	im[s.size() - 1] %= MOD;
	printf("%lld\n", im[s.size() - 1]);
	return 0;
}


#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
#include<random>
using namespace std;

#define MAX 1000002

#define MM 27
int let[MM];

char buf[MAX];

int n;
int k;

string s;

vector<pair<int, int> > v;

#define MOD 1000000007
long long int im[MAX];

int main(){
	memset(let, -1, sizeof(let));
	cin >> n >> k;
	scanf("%s", buf);
	s = buf;
	for (int i = 0; i < s.size(); i++){
		let[s[i] - 'a'] = i;
	}
	for (int i = 0; i < k; i++){
		v.push_back(make_pair(let[i], i));
	}
	sort(v.begin(), v.end());
	while (n){
		for (int i = 0; i < v.size()&&n; i++){
			s.push_back(v[i].second + 'a');
			n--;
		}
	}
	memset(let, -1, sizeof(let));
	for (int i = 0; i < s.size(); i++){
		int v = s[i] - 'a';
		int rig = let[v];
		rig = max(rig, 0);
		long long int D = 0;
		if (i){
			D += im[i - 1];
		}
		if (rig){
			D -= im[rig - 1];
		}
		if (let[v] == -1){
			D++;
		}
		im[i] = D;
		if (i){
			im[i] += im[i - 1];
		}
		if (im[i] >= MOD)im[i] %= MOD;
		let[v] = i;
	}
	im[s.size() - 1]++;
	im[s.size() - 1] %= MOD;
	printf("%lld\n", im[s.size() - 1]);
	return 0;
}


#include <cstdio>
#include <algorithm>
const int MOD = 1000000007;
int N, M, K, a[2000000], f[2000001], last[26], pattern[26];
char s[1000001];
inline void add(int &x, int y)
{
	x = x + y < MOD ? x + y : x + y - MOD;
}
int main()
{
	scanf("%d%d%s", &N, &K, s);
	while (s[M])
		M++;
	N += M;
	for (int i = 0; i < K; i++)
		last[i] = -1;
	for (int i = 0; i < M; i++)
		last[a[i] = s[i] - 'a'] = i;
	for (int i = 0; i < K; i++)
		pattern[i] = i;
	std::sort(pattern, pattern + K, [] (int x, int y) { return last[x] < last[y]; });
	for (int i = M; i < N; i = std::min(i + K, N))
		std::copy(pattern, pattern + std::min(K, N - i), a + i);
	for (int i = 0; i < K; i++)
		last[i] = N;
	f[N] = 1;
	for (int i = N - 1; ~i; i--)
	{
		last[a[i]] = i;
		f[i] = 1;
		for (int j = 0; j < K; j++)
			if (last[j] < N)
				add(f[i], f[last[j] + 1]);
	}
	printf("%d\n", f[0]);
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9+7;

int n,k;
char s[1000013];
long long dp[26];
int last[26];

int main() {
    scanf("%d%d %s",&n,&k,&s);
    for (int i=0;s[i]!='\0';i++) {
        dp[s[i]-'a'] = (1+accumulate(dp,dp+k,0LL))%MOD;
        last[s[i]-'a'] = i+1;
    }
    for (int i=MOD;i<MOD+n;i++) {
        int next = min_element(last,last+k)-last;
        dp[next] = (1+accumulate(dp,dp+k,0LL))%MOD;
        last[next] = i;
    }
    printf("%lld\n",(1+accumulate(dp,dp+k,0LL))%MOD);

    return 0;
}


 #include <bits/stdc++.h>
using namespace std;
const int md = 1000000007;
const int N = 3456789;
char s[N];
int f[N];
int last[42];

int main()
{
  int n, k;
  scanf("%d %d", &n, &k);
  scanf("%s", s + 1);
  int m = strlen(s + 1);
  for (int j = 0; j < k; j++)
    last[j] = 0;

  f[0] = 1;

  for (int i = 1; i <= m + n; i++)
  {
    f[i] = f[i - 1] * 2 % md;
    int c;
    if (i <= m)
      c = s[i] - 'a';
    else
    {
      c = -1;
      int pos = i;
      for (int cc = 0; cc < k; cc++)
      {
        if (last[cc] < pos)
        {
          pos = last[cc];
          c = cc;
        }
      }
       // cout<<c<<pos<<endl;
    }

    if (last[c] > 0)
      f[i] = (f[i] - f[last[c] - 1] + md) % md;
    last[c] = i;
     // cout<<f[i]<<" "<<last[c]<<endl;

  }
  printf("%d\n", f[m + n]);
  return 0;
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define N 1000100
#define prev ldkjfh
#define mod 1000000007
int n,k;
string t;
int dp[N];
int prev[N];
int main()
{
#ifdef home
    freopen("input.txt","r",stdin);
#endif // home
    cin >> n >> k >> t;
    int m = t.size();
    dp[0] = 1;
    memset(prev,-1,sizeof prev);
    for(int i=1;i<=m;++i)
    {
        (dp[i] = 2*dp[i-1]) %= mod;
        int &foo = prev[ t[i-1]-'a' ];
        if(~foo) (dp[i] += mod-dp[foo])%=mod;
        foo = i-1;
    }
    for(int i=1+m;i<=n+m;++i)
    {
        (dp[i] = 2*dp[i-1])%=mod;
        int foo = 1e9,bar = -1;
        for(int j=0;j<k;++j)
        {
            if(prev[j] < foo)
            {
                foo = prev[j];
                bar = j;
            }
            //dp[i] -= dp[ prev[ j ] ];
        }
        if(~foo) (dp[i] += mod-dp[ foo ]) %= mod;
        prev[ bar ] = i - 1;
    }
    cout << dp[m + n] << '\n';
}


#include<bits/stdc++.h>

using namespace std;
typedef long long ll;

#define N 2000100
#define prev ldkjfh
#define mod 1000000007
int n,k;
string t;
int dp[N];
int prev[N];
int main()
{
#ifdef home
    freopen("input.txt","r",stdin);
#endif // home
    cin >> n >> k >> t;
    int m = t.size();
    dp[0] = 1;
    memset(prev,-1,sizeof prev);
    for(int i=1;i<=m;++i)
    {
        (dp[i] = 2*dp[i-1]) %= mod;
        int &foo = prev[ t[i-1]-'a' ];
        if(~foo) (dp[i] += mod-dp[foo])%=mod;
        foo = i-1;
    }
    for(int i=1+m;i<=n+m;++i)
    {
        (dp[i] = 2*dp[i-1])%=mod;
        int foo = 1e9,bar = -1;
        for(int j=0;j<k;++j)
        {
            if(prev[j] < foo)
            {
                foo = prev[j];
                bar = j;
            }
            //dp[i] -= dp[ prev[ j ] ];
        }
        if(~foo) (dp[i] += mod-dp[ foo ]) %= mod;
        prev[ bar ] = i - 1;
    }
    cout << dp[m + n] << '\n';
}


#include <bits/stdc++.h>
using namespace std;

#define id(c) c-'a'
#define REP(i,s,t) for(int i=s;i<=t;i++)
const int MOD = 1e9+7;
const int N = 2e6+5;
typedef long long ll;
ll n,k,dp[N],pos[30];
char s[N];
//dp[i]表示前i个字符的子串种类数的最大值
int main(){
	cin>>n>>k;scanf("%s",s+1);
	int m=strlen(s+1);
	dp[0]=1;
	REP(i,1,m){
		dp[i]+=dp[i-1]*2;      //前i-1的真实子串种类数为dp[i-1]，然后再加上之前的子串以它结尾的种类数
		if(pos[id(s[i])]>0)    //如果这个字符出现过了，才需要减dp[pre[c]-1],因为在pre[c]的时候，所有pre[c]-1之前的元素计算过了一遍相同的情况(即以c为最尾端的字符所构成的字符串)
			dp[i]-=dp[pos[id(s[i])]-1];
		dp[i]%=MOD;
		pos[id(s[i])]=i;      //更新
	}
	REP(i,m+1,m+n){
		dp[i]+=dp[i-1]*2;
		int c,loc=1e9;
		REP(j,0,k-1) if(pos[j]<loc){    //查找前k个字符最后一个字符最早出现的位置
			loc=pos[j];
			c=j;
		}
		if(loc>0)dp[i]-=dp[loc-1];  //同上，如果c所对应的字符之前没有出现过，那么就不需要减去重复计算的部分(因为根本就没有重复计算)
		dp[i]%=MOD;
		pos[c]=i;
	}
	printf("%lld\n",(dp[m+n]+MOD)%MOD);
}