#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;
typedef unsigned long long ull;

#define F first
#define S second
#define en end()
#define bg begin()
#define rev reverse
#define mp make_pair
#define pb push_back
#define y1 y1234567890
#define um unordered_map
#define all(x) x.bg, x.en
#define sqr(x) ((x) * (x))
#define sz(x) (int)x.size()

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const double pi = acos(-1.0);
const double eps = (double)1e-9;

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 2000500;

char s[N];
bool u[26];
int n, m, k, last[26], dp[N], sum[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	scanf("%d %d %s", &n, &k, s + 1);

	m = strlen(s + 1);

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

	for (int i = m + 1; i <= n + m; i++) {
		for (int j = 0; j < k; j++) {
			if (!u[j]) {
				u[j] = 1;
				s[i] = char('a' + j);
				break;
			}
		}
	}

	dp[0] = sum[0] = 1;

	for (int i = 0; i < k; i++)
		last[i] = N;

	for (int i = 1; i <= n + m; i++) {
		if (s[i] < 'a' || 'z' < s[i]) {
			int mn = N;
			char c = 'a';
			for (int j = 0; j < k; j++) {
				if (last[j] < mn) {
					mn = last[j];
					c = char('a' + j);
				}
			}
			s[i] = c;
		}
		if (last[s[i] - 'a'] == N)
			dp[i] = sum[i - 1];
		else
			dp[i] = sum[i - 1] - sum[last[s[i] - 'a'] - 1];
		if (dp[i] < 0)
			dp[i] += mod;
		sum[i] = sum[i - 1] + dp[i];
		if (sum[i] >= mod)
			sum[i] -= mod;
		last[s[i] - 'a'] = i;
	}

	printf("%d", sum[n + m]);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef unsigned int ui;
typedef pair < ll, ll > pll;
typedef pair < int, ll > pil;
typedef pair < ll, int > pli;
typedef pair < int, int > pii;
typedef unsigned long long ull;

#define F first
#define S second
#define en end()
#define bg begin()
#define rev reverse
#define mp make_pair
#define pb push_back
#define y1 y1234567890
#define um unordered_map
#define all(x) x.bg, x.en
#define sqr(x) ((x) * (x))
#define sz(x) (int)x.size()

const ll inf = (ll)1e18;
const ll mod = (ll)1e9 + 7;
const double pi = acos(-1.0);
const double eps = (double)1e-9;

const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

const int N = 2000500;

char s[N];
bool u[26];
int n, m, k, last[26], dp[N], sum[N];

int main() {
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);

	//cin.tie(NULL);
	//cout.tie(NULL);
	//ios_base::sync_with_stdio(false);

	scanf("%d %d %s", &n, &k, s + 1);

	m = strlen(s + 1);

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

	for (int i = n + m; i > m; i--) {
		for (int j = 0; j < k; j++) {
			if (!u[j]) {
				u[j] = 1;
				s[i] = char('a' + j);
				break;
			}
		}
	}

	dp[0] = sum[0] = 1;

	for (int i = 0; i < k; i++)
		last[i] = N;

	for (int i = 1; i <= n + m; i++) {
		if (s[i] < 'a' || 'z' < s[i]) {
			int mn = N;
			char c = 'a';
			for (int j = 0; j < k; j++) {
				if (last[j] < mn) {
					mn = last[j];
					c = char('a' + j);
				}
			}
			s[i] = c;
		}
		if (last[s[i] - 'a'] == N)
			dp[i] = sum[i - 1];
		else
			dp[i] = sum[i - 1] - sum[last[s[i] - 'a'] - 1];
		if (dp[i] < 0)
			dp[i] += mod;
		sum[i] = sum[i - 1] + dp[i];
		if (sum[i] >= mod)
			sum[i] -= mod;
		last[s[i] - 'a'] = i;
	}

	printf("%d", sum[n + m]);

	return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

typedef long long ll;
#define cerr cout
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
inline int add(int a, int b){a += b; if(a >= MOD)a -= MOD; return a;}
inline int sub(int a, int b){a -= b; if(a < 0)a += MOD; return a;}
inline int mul(int a, int b){return (int)((long long) a * b %MOD);}
inline int binpow(int a, int b){int res = 1; while(b > 0){ if(b & 1)res = mul(res, a); a = mul(a, a);b /= 2;} return res;}
inline int inv(int a){return binpow(a, MOD - 2);}
int gcd(int a, int b, int &x, int &y){if(a == 0){x = 0, y = 1; return b;} int x1, y1;  int d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}

const int N = 1e5 + 5;
int n, k, m;

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

    cin>>n>>k;
    string s; cin>>s;
    m = s.size();
    vector<int> vis(k), v;
    for(int i=m-1;i>=0;--i)if(!vis[s[i] - 'a']){
        v.push_back(s[i] - 'a');
        vis[s[i] - 'a'] = 1;
    }

    for(int i=0;i<k;++i)if(!vis[i])v.push_back(i);
    reverse(all(v));

    int j = 0;
    for(int i=0;i<n;++i){
        s.push_back(v[j] + 'a');
        j = (k - 1)? 0 : j + 1;
    }

    int sum = 0; vector<int> val(k);
    for(int i=0;i<m + n;++i){
        int id = s[i] - 'a';
        int temp = val[id];
        val[id] = sum + 1;
        sum = sub(mul(2, sum), temp);
        sum = add(sum, 1);
    }
    sum = add(sum, 1);
    // pr(s);
    // pr(val[0]); pr(val[1]); pr(val[2]);
    cout<<sum<<"\n";
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

const int MOD = 1e9 + 7;

typedef long long ll;
#define cerr cout
#define sz(a) (int)((a).size())
#define all(x) (x).begin(), (x).end()
string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
inline int add(int a, int b){a += b; if(a >= MOD)a -= MOD; return a;}
inline int sub(int a, int b){a -= b; if(a < 0)a += MOD; return a;}
inline int mul(int a, int b){return (int)((long long) a * b %MOD);}
inline int binpow(int a, int b){int res = 1; while(b > 0){ if(b & 1)res = mul(res, a); a = mul(a, a);b /= 2;} return res;}
inline int inv(int a){return binpow(a, MOD - 2);}
int gcd(int a, int b, int &x, int &y){if(a == 0){x = 0, y = 1; return b;} int x1, y1;  int d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}

const int N = 1e5 + 5;
int n, k, m;

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

    cin>>n>>k;
    string s; cin>>s;
    m = s.size();
    vector<int> vis(k), v;
    for(int i=m-1;i>=0;--i)if(!vis[s[i] - 'a']){
        v.push_back(s[i] - 'a');
        vis[s[i] - 'a'] = 1;
    }

    for(int i=0;i<k;++i)if(!vis[i])v.push_back(i);
    reverse(all(v));

    int j = 0;
    for(int i=0;i<n;++i){
        s.push_back(v[j] + 'a');
        j = (j == k - 1)? 0 : j + 1;
    }

    int sum = 0; vector<int> val(k);
    for(int i=0;i<m + n;++i){
        // pr(sum);
        int id = s[i] - 'a';
        int temp = val[id];
        val[id] = sum + 1;
        sum = sub(mul(2, sum), temp);
        sum = add(sum, 1);
    }
    sum = add(sum, 1);
    // pr(s);
    // pr(val[0]); pr(val[1]); pr(val[2]);
    cout<<sum<<"\n";
    return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define lp(i,a,b) for(int i = a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mk make_pair
#define mkt make_tuple
#define sz size()
#define debug printf

const int MAXN = 1e6+10 , ALF = 30 ;
const ll MOD = 1e9+7 ;

using namespace std ;

int n , k ,t ;
int last[200] ;
char str[MAXN] ;
ll  tot[MAXN] ;
priority_queue< int, vector<int> , greater<int> > fila ;

int main()
{
	memset(last,-1,sizeof last) ;

	scanf("%d%d", &n , &k) ;
	scanf("%s", str) ;

	t = strlen(str);

	for(int i = t ; i > 0 ; i-- ) str[i] = str[i-1] ;

	tot[0] = 1LL ;

	lp(i,1,t+1)
	{
		if( last[ str[i] ] == -1 )
			tot[i] = tot[i-1] ;
		else tot[i] = (tot[i-1] - tot[ last[ str[i] ]-1 ] + MOD) % MOD ;

		tot[i] = ( tot[i] + tot[i-1] ) % MOD ;
		last[ str[i] ] = i ;

	}

	for(int i = 1 , b = 'a' ; i <= k ; i++ , b++ )
		if( n>0 && last[b] == -1 )
		{

			tot[++t] = tot[t-1] ;
			tot[t] = ( tot[t-1] + tot[t] ) % MOD ;
			last[b] = t ;
			n-- ;

		}

	if( n == 0 )
	{
		printf("%lld\n" , tot[t] ) ;
		return 0 ;
	}

	for(int i = 1 , b = 'a' ; i <= k ; i++ , b++ )
		fila.push( last[b] ) ;

	while( n-- )
	{

		int cur = fila.top() ;
		fila.pop() ;

		tot[++t] = (tot[t-1] - tot[cur-1]+MOD ) % MOD ;
		tot[t] = ( tot[t] + tot[t-1] ) % MOD ;

		fila.push( t ) ;

	}

	printf("%lld\n", tot[t] ) ;

}


#include <bits/stdc++.h>

#define pb push_back
#define lp(i,a,b) for(int i = a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mk make_pair
#define mkt make_tuple
#define sz size()
#define debug printf

const int MAXN = 2e6+10 , ALF = 30 ;
const ll MOD = 1e9+7 ;

using namespace std ;

int n , k ,t ;
int last[200] ;
char str[MAXN] ;
ll  tot[MAXN] ;
priority_queue< int, vector<int> , greater<int> > fila ;

int main()
{
	memset(last,-1,sizeof last) ;

	scanf("%d%d", &n , &k) ;
	scanf("%s", str) ;

	t = strlen(str);

	for(int i = t ; i > 0 ; i-- ) str[i] = str[i-1] ;

	tot[0] = 1LL ;

	lp(i,1,t+1)
	{
		if( last[ str[i] ] == -1 )
			tot[i] = tot[i-1] ;
		else tot[i] = (tot[i-1] - tot[ last[ str[i] ]-1 ] + MOD) % MOD ;

		tot[i] = ( tot[i] + tot[i-1] ) % MOD ;
		last[ str[i] ] = i ;

	}

	for(int i = 1 , b = 'a' ; i <= k ; i++ , b++ )
		if( n>0 && last[b] == -1 )
		{

			tot[++t] = tot[t-1] ;
			tot[t] = ( tot[t-1] + tot[t] ) % MOD ;
			last[b] = t ;
			n-- ;

		}

	if( n == 0 )
	{
		printf("%lld\n" , tot[t] ) ;
		return 0 ;
	}

	for(int i = 1 , b = 'a' ; i <= k ; i++ , b++ )
		fila.push( last[b] ) ;

	while( n-- )
	{

		int cur = fila.top() ;
		fila.pop() ;

		tot[++t] = (tot[t-1] - tot[cur-1]+MOD ) % MOD ;
		tot[t] = ( tot[t] + tot[t-1] ) % MOD ;

		fila.push( t ) ;

	}

	printf("%lld\n", tot[t] ) ;

}


#include <bits/stdc++.h>

#define pb push_back
#define lp(i,a,b) for(int i = a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mk make_pair
#define mkt make_tuple
#define sz size()
#define debug printf

const int MAXN = 1e6+10 , ALF = 30 ;
const ll MOD = 1e9+7 ;

using namespace std ;

int n , k ,t ;
int last[200] ;
char str[MAXN] ;
ll  tot[MAXN] ;
priority_queue< int, vector<int> , greater<int> > fila ;

int main()
{
	memset(last,-1,sizeof last) ;

	scanf("%d%d", &n , &k) ;
	scanf("%s", str) ;

	t = strlen(str);

	for(int i = t ; i > 0 ; i-- ) str[i] = str[i-1] ;

	tot[0] = 1LL ;

	lp(i,1,t+1)
	{
		if( last[ str[i] ] == -1 )
			tot[i] = tot[i-1] ;
		else tot[i] = tot[i-1] - tot[ last[ str[i] ]-1 ] ;

		tot[i] = ( tot[i] + tot[i-1] ) % MOD ;
		last[ str[i] ] = i ;

	}

	for(int i = 1 , b = 'a' ; i <= k ; i++ , b++ )
		if( n>0 && last[b] == -1 )
		{

			tot[++t] = tot[t-1] ;
			tot[t] = ( tot[t-1] + tot[t] ) % MOD ;
			last[b] = t ;
			n-- ;

		}

	if( n == 0 )
	{
		printf("%lld\n" , tot[t] ) ;
		return 0 ;
	}

	for(int i = 1 , b = 'a' ; i <= k ; i++ , b++ )
		fila.push( last[b] ) ;

	while( n-- )
	{

		int cur = fila.top() ;
		fila.pop() ;

		tot[++t] = tot[t-1] - tot[cur-1] ;
		tot[t] = ( tot[t] + tot[t-1] ) % MOD ;

		fila.push( t ) ;

	}

	printf("%lld\n", tot[t] ) ;

}


#include <bits/stdc++.h>

#define pb push_back
#define lp(i,a,b) for(int i = a;i<b;i++)
#define ll long long
#define pii pair<int,int>
#define ff first
#define ss second
#define mk make_pair
#define mkt make_tuple
#define sz size()
#define debug printf

const int MAXN = 1e6+10 , ALF = 30 , MOD = 1e9+7 ;

using namespace std ;

int n , k ,t ;
int last[200] , tot[MAXN] ;
char str[MAXN] ;
priority_queue< int, vector<int> , greater<int> > fila ;

int fast(int exp)
{

	int aux ;

	if(exp == 0) return 1 ;

	if( exp%2 == 0 )
	{
		aux = fast(exp/2) ;
		return (aux*aux) % MOD ;
	}

	aux = fast(exp-1) ;

	return ( 2*aux ) % MOD ;

}

int main()
{
	memset(last,-1,sizeof last) ;

	scanf("%d%d", &n , &k) ;
	scanf("%s", str) ;

	t = strlen(str);

	for(int i = t ; i > 0 ; i-- ) str[i] = str[i-1] ;

	tot[0] = 1 ;

	lp(i,1,t+1)
	{
		if( last[ str[i] ] == -1 )
			tot[i] = tot[i-1] ;
		else tot[i] = tot[i-1] - tot[ last[ str[i] ]-1 ] ;

		tot[i] = ( tot[i] + tot[i-1] ) % MOD ;
		last[ str[i] ] = i ;

	}

	for(int i = 1 , b = 'a' ; i <= k ; i++ , b++ )
		if( n>0 && last[b] == -1 )
		{

			tot[++t] = tot[t-1] ;
			tot[t] = ( tot[t-1] + tot[t] ) % MOD ;
			last[b] = t ;
			n-- ;

		}

	if( n == 0 )
	{
		printf("%d\n" , tot[t] ) ;
		return 0 ;
	}

	for(int i = 1 , b = 'a' ; i <= k ; i++ , b++ )
		fila.push( last[b] ) ;

	while( n-- )
	{

		int cur = fila.top() ;
		fila.pop() ;

		tot[++t] = tot[t-1] - tot[cur-1] ;
		tot[t] = ( tot[t] + tot[t-1] ) % MOD ;

		fila.push( t ) ;

	}

	printf("%d\n", tot[t] ) ;

}


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

const int maxn = 2e6 + 5, mod = 1e9 + 7;
int dp[maxn], prv[26];
char s[maxn];

int main() {
    int n, k; scanf("%d %d", &n, &k);
    scanf("%s", s);
    int m = strlen(s);
    dp[0] = 1;
    for (int i = 1; i <= m; ++i) {
        dp[i] = dp[i - 1] * 2ll % mod;
        // printf("s[%d] = %c\n", i - 1, s[i - 1]);
        if (prv[s[i - 1] - 'a']) dp[i] = (dp[i] - dp[prv[s[i - 1] - 'a']] + 1 + mod) % mod;
        prv[s[i - 1] - 'a'] = i;
        // printf("dp[%d] = %d\n", i, dp[i]);
    }
    for (int i = m + 1; i <= m + n; ++i) {
        char c = 'a';
        for (char j = 'b'; j < 'a' + k; ++j) if (prv[j - 'a'] < prv[c - 'a']) c = j;
        dp[i] = dp[i - 1] * 2ll % mod;
        if (prv[c - 'a']) dp[i] = (dp[i] - dp[prv[c - 'a']] + 1 + mod) % mod;
        prv[c - 'a'] = i;
    }
    printf("%d\n", dp[m + n]);
    return 0;
}


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

const int maxn = 2e6 + 5, mod = 1e9 + 7;
int dp[maxn], prv[26];
char s[maxn];

int main() {
    int n, k; scanf("%d %d", &n, &k);
    scanf("%s", s);
    int m = strlen(s);
    dp[0] = 1;
    for (int i = 1; i <= m; ++i) {
        dp[i] = dp[i - 1] * 2ll % mod;
        // printf("s[%d] = %c\n", i - 1, s[i - 1]);
        if (prv[s[i - 1] - 'a']) dp[i] = (dp[i] - dp[prv[s[i - 1] - 'a'] - 1] + mod) % mod;
        prv[s[i - 1] - 'a'] = i;
        // printf("dp[%d] = %d\n", i, dp[i]);
    }
    for (int i = m + 1; i <= m + n; ++i) {
        char c = 'a';
        for (char j = 'b'; j < 'a' + k; ++j) if (prv[j - 'a'] < prv[c - 'a']) c = j;
        dp[i] = dp[i - 1] * 2ll % mod;
        if (prv[c - 'a']) dp[i] = (dp[i] - dp[prv[c - 'a'] - 1] + mod) % mod;
        prv[c - 'a'] = i;
    }
    printf("%d\n", dp[m + n]);
    return 0;
}


#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector

int n,m,k;
string s;
int last[30];
int dp[N],pref[N];
void solve()
{
    cin>>n>>k;
    cin>>s;
    m = s.size();
    st(last,-1);
    forn(i,0,m-1)last[s[i]-'a']=i;

    forn(i,m,m+n-1)
    {
        int l = 1e10 , val = -1;
        forn(j,0,k-1)
        {
            if(last[j]<l)
            {
                l = last[i];
                val = j;
            }
        }
        s+=char('a'+val);
    }
  //  cout<<s<<"\n";
    dp[0] = 1;
    pref[0] = 1;
    st(last,0);
    forn(i,1,m+n)
    {
        int x = s[i-1]-'a';
        if(last[x] == 0);
        else
        {
            dp[i]-=pref[last[x]-1];
        }
        dp[i]+=pref[i-1];
        pref[i] = pref[i-1]+dp[i];
        last[x] = i;
    }
  //  forn(i,1,m+n)cout<<pref[i]<<" ";nl;
    cout<<pref[n+m];

}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;

}

//       g++ -g c.cpp ; ./a.exe


#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector

int n,m,k;
string s;
int last[30];
int dp[N],pref[N];
void solve()
{
    cin>>n>>k;
    cin>>s;
    m = s.size();
    st(last,-1);
    forn(i,0,m-1)last[s[i]-'a']=i;

    forn(i,m,m+n-1)
    {
        int l = 1e10 , val = -1;
        forn(j,0,k-1)
        {
            if(last[j]<l)
            {
                l = last[j];
                val = j;
            }
        }
        s+=('a'+val);
        last[val] = i;
    }
   // cout<<s<<"\n";
    dp[0] = 1;
    pref[0] = 1;
    st(last,0);
    forn(i,1,m+n)
    {
        int x = s[i-1]-'a';
        if(last[x] == 0);
        else
        {
            dp[i]+=-pref[last[x]-1]+MOD;
        }
        dp[i]+=pref[i-1];
        dp[i]%=MOD;
        pref[i] = pref[i-1]+dp[i];
        pref[i]%=MOD;
        last[x] = i;
    }
  //  forn(i,1,m+n)cout<<pref[i]<<" ";nl;
    cout<<pref[n+m];

}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;

}

//       g++ -g c.cpp ; ./a.exe


#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector

int n,m,k;
string s;
int last[30];
int dp[N],pref[N];
void solve()
{
    cin>>n>>k;
    cin>>s;
    m = s.size();
    st(last,-1);
    forn(i,0,m-1)last[s[i]-'a']=i;

    forn(i,m,m+n-1)
    {
        int l = 1e10 , val = -1;
        forn(j,0,k-1)
        {
            if(last[j]<l)
            {
                l = last[i];
                val = j;
            }
        }
        s+=('a'+val);
        last[val] = i;
    }
  //  cout<<s<<"\n";
    dp[0] = 1;
    pref[0] = 1;
    st(last,0);
    forn(i,1,m+n)
    {
        int x = s[i-1]-'a';
        if(last[x] == 0);
        else
        {
            dp[i]-=pref[last[x]-1];
        }
        dp[i]+=pref[i-1];
        pref[i] = pref[i-1]+dp[i];
        last[x] = i;
    }
  //  forn(i,1,m+n)cout<<pref[i]<<" ";nl;
    cout<<pref[n+m];

}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;

}

//       g++ -g c.cpp ; ./a.exe


#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector

int n,m,k;
string s;
int last[30];
int dp[N],pref[N];
void solve()
{
    cin>>n>>k;
    cin>>s;
    m = s.size();
    st(last,-1);
    forn(i,0,m-1)last[s[i]-'a']=i;

    forn(i,m,m+n-1)
    {
        int l = 1e10 , val = -1;
        forn(j,0,k-1)
        {
            if(last[j]<l)
            {
                l = last[j];
                val = j;
            }
        }
        s+=('a'+val);
        last[val] = i;
    }
   // cout<<s<<"\n";
    dp[0] = 1;
    pref[0] = 1;
    st(last,0);
    forn(i,1,m+n)
    {
        int x = s[i-1]-'a';
        if(last[x] == 0);
        else
        {
            dp[i]-=pref[last[x]-1]+MOD;
        }
        dp[i]+=pref[i-1];
        dp[i]%=MOD;
        pref[i] = pref[i-1]+dp[i];
        pref[i]%=MOD;
        last[x] = i;
    }
  //  forn(i,1,m+n)cout<<pref[i]<<" ";nl;
    cout<<pref[n+m];

}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;

}

//       g++ -g c.cpp ; ./a.exe


#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 3014159
#define  vi vector<int>
#define  v  vector

int n,m,k;
string s;
int last[30];
int dp[N],pref[N];
void solve()
{
    cin>>n>>k;
    cin>>s;
    m = s.size();
    st(last,-1);
    forn(i,0,m-1)last[s[i]-'a']=i;

    forn(i,m,m+n-1)
    {
        int l = 1e10 , val = -1;
        forn(j,0,k-1)
        {
            if(last[j]<l)
            {
                l = last[j];
                val = j;
            }
        }
        s+=('a'+val);
        last[val] = i;
    }
   // cout<<s<<"\n";
    dp[0] = 1;
    pref[0] = 1;
    st(last,0);
    forn(i,1,m+n)
    {
        int x = s[i-1]-'a';
        if(last[x] == 0);
        else
        {
            dp[i]+=-pref[last[x]-1]+MOD;
        }
        dp[i]+=pref[i-1];
        dp[i]%=MOD;
        pref[i] = pref[i-1]+dp[i];
        pref[i]%=MOD;
        last[x] = i;
    }
  //  forn(i,1,m+n)cout<<pref[i]<<" ";nl;
    cout<<pref[n+m];

}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;

}

//       g++ -g c.cpp ; ./a.exe


#include<bits/stdc++.h>
using namespace         std;
#define                 int long long
#define                 pb push_back
#define                 mp make_pair
#define st(arr,a)       memset(arr,a,sizeof arr)
#define                 nl cout<<endl
#define                 real signed
#define                 endl '\n'
#define bitcount(x)     __builtin_popcountll(x)
const int MOD = 1000000007ll;
#define forn(i,a,b)     for(int i=a;i<=b;i++)
#define rfor(i,a,b)     for(int i=a;i>=b;i--)
#define all(x)          x.begin() , x.end()
#define pi pair<int,int>
#define X first
#define Y second
#define N 1014159
#define  vi vector<int>
#define  v  vector

int n,m,k;
string s;
int last[30];
int dp[N],pref[N];
void solve()
{
    cin>>n>>k;
    cin>>s;
    m = s.size();
    st(last,-1);
    forn(i,0,m-1)last[s[i]-'a']=i;

    forn(i,m,m+n-1)
    {
        int l = 1e10 , val = -1;
        forn(j,0,k-1)
        {
            if(last[j]<l)
            {
                l = last[j];
                val = j;
            }
        }
        s+=('a'+val);
        last[val] = i;
    }
   // cout<<s<<"\n";
    dp[0] = 1;
    pref[0] = 1;
    st(last,0);
    forn(i,1,m+n)
    {
        int x = s[i-1]-'a';
        if(last[x] == 0);
        else
        {
            dp[i]-=pref[last[x]-1]+MOD;
        }
        dp[i]+=pref[i-1];
        dp[i]%=MOD
        pref[i] = pref[i-1]+dp[i];
        pref[i]%=MOD;
        last[x] = i;
    }
  //  forn(i,1,m+n)cout<<pref[i]<<" ";nl;
    cout<<pref[n+m];

}

signed main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

    return 0;

}

//       g++ -g c.cpp ; ./a.exe


#include <iostream>
#include <vector>
#include <cstring>
const int N = 2000000+10;
const int MOD = 1e9+7;
using namespace std;
typedef long long LL;
int n,m,k;
int dp[N][26]; char s[N];
int pre[26];

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

    for(int i=m+1;i<=n+m;i++){
        int mn=N,bst;
        for(int j=0;j<k;j++){
            if(pre[j]<mn){
                mn=pre[j]; bst=j;
            }
        }
        pre[bst]=i;
        int sum=1;
        for(int j=0;j<k;j++){
            if(j!=bst) {
                dp[i][j]=dp[i-1][j];
                sum=(sum+dp[i-1][j])%MOD;
            }
        }
        dp[i][bst]=(sum+dp[i-1][bst])%MOD;
    }
    LL ans=0;
    for(int i=0;i<k;i++)ans=(ans+dp[n+m][i])%MOD;
    ans=(ans+1)%MOD;
    cout<<ans<<endl;
}


#include <iostream>
#include <vector>
#include <cstring>
const int N = 2000000+10;
const int MOD=1e9+7;
using namespace std;
typedef long long LL;
int n,m,k;
int dp[N][26]; char s[N];
int pre[26];

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

    for(int i=m+1;i<=n+m;i++){
        int mn=N,bst;
        for(int j=0;j<26;j++){
            if(pre[j]<mn){
                mn=pre[j]; bst=j;
            }
        }
        pre[bst]=i;
        int sum=1;
        for(int j=0;j<k;j++){
            if(j!=bst) {
                dp[i][j]=dp[i-1][j];
                sum=(sum+dp[i-1][j])%MOD;
            }
        }
        dp[i][bst]=(sum+dp[i-1][bst])%MOD;
    }
    LL ans=0;
    for(int i=0;i<k;i++)ans=(ans+dp[n+m][i])%MOD;
    ans=(ans+1)%MOD;
    cout<<ans<<endl;
}


#include <bits/stdc++.h>

using namespace std;

#define mp make_pair
#define pb push_back
#define rep(i,n) for(int i = 0; i < (n); i++)
#define re return
#define fi first
#define se second
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()
#define sqrt(x) sqrt(abs(x))
#define y0 y3487465
#define y1 y8687969
#define j0 j5743892
#define j1 j542893
#define prev PREV
#define next NEXT

typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef double D;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
typedef vector<vi> vvi;

template<class T> T abs(T x) { re x > 0 ? x : -x; }
template<class T> T gcd(T a, T b) { re a ? gcd (b % a, a) : b; }
template<class T> T sqr(T a) { re a * a; }
template<class T> T sgn(T a) { re a > 0 ? 1 : (a < 0 ? -1 : 0); }

#define filename ""

const int mod = 1000*1000*1000+7;

int n;
int m;
int last[26];
int res[2000100];
int sum[2000100];
int k;
string s;

int main () {
	cin >> n >> k;
	cin >> s;
	n += sz (s);
	res[0] = 1;
	sum[1] = 1;
	for (int i = 1; i <= n; i++)
		if (i <= sz (s)) {
			res[i] = (sum[i] - sum[last[s[i - 1] - 'a']] + mod) % mod;
			sum[i + 1] = (sum[i] + res[i]) % mod;
			last[s[i - 1] - 'a'] = i;
		} else {
			int best = 0;
			for (int j = 0; j < k; j++)
				if (last[best] > last[j])
					best = j;
			res[i] = (sum[i] - sum[last[best]] + mod) % mod;
			sum[i + 1] = (sum[i] + res[i]) % mod;
			last[best] = i;
		}
	printf ("%d\n", sum[n + 1]);
	return 0;
}


#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int N=1e6+5,MAX_K=26,P=1e9+7;
int last[MAX_K],dp[MAX_K];
char str[N];
inline void mod_add(int &a,int b){
    if((a+=b)>=P)a-=P;
}
int main(){
    int n,m,K,sum=0,ans=1;
    scanf("%d%d%s",&m,&K,str);
    n=strlen(str);
    for(int i=0;i<K;++i){
        dp[i]=0;
        last[i]=-1;
    }
    for(int i=0;i<n;++i){
        last[str[i]-='a']=i;
        int tmp=dp[str[i]];
        dp[str[i]]=(sum+1)%P;
        sum=(((sum<<1)+1-tmp)%P+P)%P;
    }
    for(int i=0;i<m;++i){
        int ptr=-1;
        for(int j=0;j<K;++j)
            if(ptr==-1||last[j]<last[ptr])ptr=j;
        int tmp=dp[ptr];
        dp[ptr]=(sum+1)%P;
        sum=(((sum<<1)+1-tmp)%P+P)%P;
        last[ptr]=n+i;
    }
    for(int i=0;i<K;++i)
        mod_add(ans,dp[i]);
    printf("%d\n",ans);
    return 0;
}
/*

*/


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1000000007;
int n,k;
string s;
int lt[256];
ll dp[2000006];
int main()
{
    ios::sync_with_stdio(false);
    cin>>n>>k;
    cin>>s;
    memset(lt,-1,sizeof(lt));
    for(int i=1;i<=s.size();i++)
	{
        if(lt[s[i-1]]==-1)
		{
            dp[i]=(dp[i-1]*2+1)%mod;
            lt[s[i-1]]=i;
        }else
		{
            dp[i]=(dp[i-1]*2-dp[lt[s[i-1]]-1]+mod)%mod;
            lt[s[i-1]]=i;
        }
    }
    int dst=s.size()+n;
    for(int i=s.size()+1;i<=dst;i++)
	{
        char res;
        int cur=1e9;
        for(char c='a';c<='a'+k-1;c++)
		{
            if(lt[c]<cur)
			{
                cur=lt[c];
                res=c;
            }
        }
        if(lt[res]==-1)
		{
            dp[i]=(dp[i-1]*2+1)%mod;
            lt[res]=i;
        }
		else
		{
            dp[i]=(dp[i-1]*2-dp[lt[res]-1]+mod)%mod;
            lt[res]=i;
        }
        s+=res;
    }
    cout<<(dp[dst]+1)%mod<<endl;
    return 0;
}
//


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 200001

int dp[N];
int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,k;
    cin >> n >> k;
    int m;
    string s;
    cin >> s;
    m = s.length();
    vector<int> last(k,-1);
    dp[0] = 1;
    for(int i = 1;i <= m;i++)
    {
        int z = (int)(s[i - 1] - 'a');
        dp[i] = (2 * dp[i-1]);

        if(last[z] != -1)
        {
            dp[i] = (dp[i] - dp[last[z]]) % mod;
        }
        dp[i] = (dp[i] + mod )%mod;
        last[z] = i - 1;
    }
    for(int i = m + 1;i <= m + n;i++)
    {
        int u = m;
        int c = 1;
        for(int j = 0;j < k;j++)
        {
            if(last[j] < u)
            {
                u = last[j];
                c = j;
            }
        }
        dp[i] = (2 * dp[i-1]);
        if(u != -1)
            dp[i] = (dp[i] - dp[u]) % mod;
        dp[i] = (dp[i] + mod )%mod;
        last[c] = i;
    }
    cout << dp[m + n];

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 2000001

int dp[N];
int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,k;
    cin >> n >> k;
    int m;
    string s;
    cin >> s;
    m = s.length();
    vector<int> last(k,-1);
    dp[0] = 1;
    for(int i = 1;i <= m;i++)
    {
        int z = (int)(s[i - 1] - 'a');
        dp[i] = (2 * dp[i-1]);

        if(last[z] != -1)
        {
            dp[i] = (dp[i] - dp[last[z]]) % mod;
        }
        dp[i] = (dp[i] + mod )%mod;
        last[z] = i - 1;
    }
    for(int i = m + 1;i <= m + n;i++)
    {
        int u = i;
        int c = 1;
        for(int j = 0;j < k;j++)
        {
            if(last[j] < u)
            {
                u = last[j];
                c = j;
            }
        }
        dp[i] = (2 * dp[i-1]);
        if(u != -1)
            dp[i] = (dp[i] - dp[u]) % mod;
        dp[i] = (dp[i] + mod )%mod;
        last[c] = i - 1;
    }
    cout << dp[m + n];

}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define mod 1000000007
#define inf (1LL<<61)
#define int long long
typedef long long ll;
#define ld long double
#define N 200001

int dp[N];
int32_t main()
{
    IOS;
    #ifndef ONLINE_JUDGE
    freopen("int.txt","r",stdin);
    freopen("out.txt","w",stdout);
    #endif

    int n,k;
    cin >> n >> k;
    int m;
    string s;
    cin >> s;
    m = s.length();
    vector<int> last(k,-1);
    dp[0] = 1;
    for(int i = 1;i <= m;i++)
    {
        int z = (int)(s[i - 1] - 'a');
        dp[i] = (2 * dp[i-1]);

        if(last[z] != -1)
        {
            dp[i] = (dp[i] - dp[last[z]]) % mod;
        }
        dp[i] = (dp[i] + mod )%mod;
        last[z] = i - 1;
    }
    for(int i = m + 1;i <= m + n;i++)
    {
        int u = i;
        int c = 1;
        for(int j = 0;j < k;j++)
        {
            if(last[j] < u)
            {
                u = last[j];
                c = j;
            }
        }
        dp[i] = (2 * dp[i-1]);
        if(u != -1)
            dp[i] = (dp[i] - dp[u]) % mod;
        dp[i] = (dp[i] + mod )%mod;
        last[c] = i - 1;
    }
    cout << dp[m + n];

}


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define repd(i,k) for(ll i=k;i>=0;i--)
#define rep(i,k) for(ll i=0;i<k;i++)
#define repn(i,k1,k2) for(ll i=k1;i<k2;i++)
#define sz(x) (ll)(x).size()
#define ff first
#define ss second

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ee6 (ll)1000001
#define ee5 (ll)100001

#define tt ll t;cin>>t; while(t--)
typedef long long int ll;

typedef pair<ll, ll> pr;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pr> vpr;
typedef vector<vpr>vvpr;
typedef vector<vi> vvi;
typedef map<ll,ll> MPII;
typedef set<ll> SETI;
typedef multiset<ll> MSETI;
//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;

ll powmod(ll a, ll e) {
	if (e == 0) return 1;
	ll x = powmod(a * a % MOD, e >> 1);
	return e & 1 ? x * a % MOD : x;
}
int dp[2*ee6];
int main()
{
	#if !ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,m;cin>>n>>m;
	string s;cin>>s;

	vi lastoccur(26,-1);
	vector<pair<int,char> >v;
	for(int i=s.size()-1;i>=0;i--)
		if(lastoccur[s[i]-'a']==-1)
		{lastoccur[s[i]-'a']=i;v.pb(mp(i,s[i]));}

	for(char ch='a';ch<'a'+m;ch++)
		if(lastoccur[ch-'a']==-1)
			v.pb(mp(-1,ch));

	sort(all(v));
	for(int i=0;i<n;i++){s.append(1,v[i%m].ss);}

	cout<<s<<" ";

	vi occur(26,-1);

	dp[0]=1;
	for(int i=1;i<=s.size();i++)
	{
		dp[i]=2*dp[i-1];
		if(occur[s[i-1]-'a']!=-1)
			dp[i]-=dp[occur[s[i-1]-'a']];
		occur[s[i-1]-'a']=i-1;
	}
	//for(int i=1;i<=4;i++)cout<<dp[i]<<" ";
cout<<dp[s.size()];
}


#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

using namespace std;

/*******  All Required define Pre-Processors and typedef Constants *******/
#define scd(t) scanf("%d",&t)
#define scld(t) scanf("%ld",&t)
#define sclld(t) scanf("%lld",&t)
#define scc(t) scanf("%c",&t)
#define scs(t) scanf("%s",t)
#define scf(t) scanf("%f",&t)
#define sclf(t) scanf("%lf",&t)
#define mem(a, b) memset(a, (b), sizeof(a))
#define repd(i,k) for(ll i=k;i>=0;i--)
#define rep(i,k) for(ll i=0;i<k;i++)
#define repn(i,k1,k2) for(ll i=k1;i<k2;i++)
#define sz(x) (ll)(x).size()
#define ff first
#define ss second

#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.end(), cont.begin()
#define mp make_pair
#define pb push_back
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
#define ee6 (ll)1000001
#define ee5 (ll)100001

#define tt ll t;cin>>t; while(t--)
typedef long long int ll;

typedef pair<ll, ll> pr;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef vector<pr> vpr;
typedef vector<vpr>vvpr;
typedef vector<vi> vvi;
typedef map<ll,ll> MPII;
typedef set<ll> SETI;
typedef multiset<ll> MSETI;
//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;

ll powmod(ll a, ll e) {
	if (e == 0) return 1;
	ll x = powmod(a * a % MOD, e >> 1);
	return e & 1 ? x * a % MOD : x;
}
int dp[2*ee6];
int main()
{
	#if !ONLINE_JUDGE
	freopen("in.txt","r",stdin);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n,m;cin>>n>>m;
	string s;cin>>s;

	vi lastoccur(26,-1);
	vector<pair<int,char> >v;
	for(int i=s.size()-1;i>=0;i--)
		if(lastoccur[s[i]-'a']==-1)
		{lastoccur[s[i]-'a']=i;v.pb(mp(i,s[i]));}

	for(char ch='a';ch<'a'+m;ch++)
		if(lastoccur[ch-'a']==-1)
			v.pb(mp(-1,ch));

	sort(all(v));
	for(int i=0;i<n;i++){s=s+v[i%m].ss;}

	//cout<<s<<" ";

	vi occur(26,-1);

	dp[0]=1;
	for(int i=1;i<=s.size();i++)
	{
		dp[i]=2*dp[i-1];
		if(occur[s[i-1]-'a']!=-1)
			dp[i]-=dp[occur[s[i-1]-'a']];
		occur[s[i-1]-'a']=i-1;
	}
	//for(int i=1;i<=4;i++)cout<<dp[i]<<" ";
cout<<dp[s.size()];
}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StringsOfPower {

    public static void main(String [] args) {
        Scanner in = new Scanner(System.in) ;
        String heavymetal = in.next();
        int start = 0;
        int end = heavymetal.length() - 1;

        List<Integer> heavy = new ArrayList<Integer>();
        int match = 0;
        while(start < end && match != -1) {
            String  heavymetals = heavymetal.substring(start);
            match  = heavymetals.indexOf("heavy");
            if(match >=0 ){
                heavy.add(start+match);
                start += match+ 5;
            }
        }
        start = 0;
        end = heavymetal.length();

        List<Integer> metal = new ArrayList<Integer>();
        match = 0;
        while(start < end  && match != -1) {
            String  heavymetals = heavymetal.substring(start);
            match  = heavymetals.indexOf("metal");
            if(match >=0 ){
                metal.add(start+match);
                start += match + 5;
            }

           // System.out.println("yes");
        }

        /*
        for(int i=0;i<heavy.size();i++) {
            System.out.println(heavy.get(i));
        }
        System.out.println();

        for(int i=0;i<metal.size();i++) {
            System.out.println(metal.get(i));
        }*/

        int total =0;
        for(int j= 0; j <metal.size(); j++) {
            int count =0;
            for(int m=0; m<heavy.size();m++) {
                if(metal.get(j) > heavy.get(m)) {
                    count++;
                }else{
                    break;
                }
            }
             total += count;
        }

        System.out.println(total);
    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StringsOfPower {
    public static void main(String [] args) {
        Scanner in = new Scanner(System.in) ;
        String heavymetal = in.next();
        long total =0;
        List<Integer> heavy = new ArrayList<>();
        int current = 0;

        while(current < heavymetal.length()) {
            if(current<heavymetal.length() && current+4 < heavymetal.length()) {
                if ((heavymetal.charAt(current) == 'h') && (heavymetal.charAt(current+1) == 'e') && (heavymetal.charAt(current+2) == 'a') &&
                (heavymetal.charAt(current+3) == 'v') && (heavymetal.charAt(current+4) == 'y')) {
                    heavy.add(current);
                    current= current+5;
                }else if ((heavymetal.charAt(current) == 'm') && (heavymetal.charAt(current+1) == 'e') && (heavymetal.charAt(current+2) == 't') &&
                        (heavymetal.charAt(current+3) == 'a') && (heavymetal.charAt(current+4) == 'l')) {
                    current= current+5;
                    total= total+ heavy.size();
                }else {
                    current++;
                }
            }else {
                current++;
            }
        }

        System.out.println(total);
    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StringsOfPower {

    public static void main(String [] args) {
        Scanner in = new Scanner(System.in);
        String heavymetal = in.next();
        int start = 0;
        int end = heavymetal.length() - 1;

        List<Integer> heavy = new ArrayList<Integer>();
        List<Integer> metal = new ArrayList<Integer>();
        int matchHeavy = 0;
        int matchMetal = 0;
        while (start < end || (matchHeavy != -1 && matchMetal != -1)) {
            String heavymetals = heavymetal.substring(start);
            if(matchHeavy != -1) {
                matchHeavy = heavymetals.indexOf("heavy");
            }
            if(matchMetal != -1) {
                matchMetal = heavymetals.indexOf("metal");
            }
           // System.out.println(start);
            if (matchHeavy == -1 && matchMetal == -1) {
                break;
            }

            if(matchHeavy != -1 && matchMetal== -1 ) {
                heavy.add(start + matchHeavy);
                start += matchHeavy + 5;
            }else if(matchMetal != -1 && matchHeavy== -1 ) {
                metal.add(start + matchMetal);
                start += matchMetal + 5;
            }else if (matchHeavy != -1 && (matchHeavy <= matchMetal)) {
                heavy.add(start + matchHeavy);
                start += matchHeavy + 5;
            } else if (matchMetal != -1 && (matchMetal < matchHeavy)) {
                metal.add(start + matchMetal);
                start += matchMetal + 5;
            }

          //  System.out.println(start);

        }

        int total = 0;
        for (int j = 0; j < metal.size(); j++) {
            int count = 0;
            for (int m = 0; m < heavy.size(); m++) {
                if (metal.get(j) > heavy.get(m)) {
                    count++;
                } else {
                    break;
                }
            }
            total += count;
        }

        System.out.println(total);

    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StringsOfPower {
    public static void main(String [] args) {
        Scanner in = new Scanner(System.in) ;
        String heavymetal = in.next();
        int total =0;
        List<Integer> heavy = new ArrayList<>();
        List<Integer> metal = new ArrayList<>();
        int current = 0;

        while(current < heavymetal.length()) {
            if(current<heavymetal.length() && current+4 < heavymetal.length()) {
                if ((heavymetal.charAt(current) == 'h') && (heavymetal.charAt(current+1) == 'e') && (heavymetal.charAt(current+2) == 'a') &&
                (heavymetal.charAt(current+3) == 'v') && (heavymetal.charAt(current+4) == 'y')) {
                    heavy.add(current);
                    current= current+4;
                }else if ((heavymetal.charAt(current) == 'm') && (heavymetal.charAt(current+1) == 'e') && (heavymetal.charAt(current+2) == 't') &&
                        (heavymetal.charAt(current+3) == 'a') && (heavymetal.charAt(current+4) == 'l')) {
                    metal.add(current);
                    current= current+4;
                    total+= heavy.size();
                }
            }
            current++;
        }

        System.out.println(total);
    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StringsOfPower {
    public static void main(String [] args) {
        Scanner in = new Scanner(System.in) ;
        String heavymetal = in.next();
        int total =0;
        List<Integer> heavy = new ArrayList<>();
        List<Integer> metal = new ArrayList<>();
        int current = 0;

        while(current < heavymetal.length()) {
            if(current<heavymetal.length() && current+4 < heavymetal.length()) {
                if ((heavymetal.charAt(current) == 'h') && (heavymetal.charAt(current+1) == 'e') && (heavymetal.charAt(current+2) == 'a') &&
                (heavymetal.charAt(current+3) == 'v') && (heavymetal.charAt(current+4) == 'y')) {
                    heavy.add(current);
                    current= current+4;
                }else if ((heavymetal.charAt(current) == 'm') && (heavymetal.charAt(current+1) == 'e') && (heavymetal.charAt(current+2) == 't') &&
                        (heavymetal.charAt(current+3) == 'a') && (heavymetal.charAt(current+4) == 'l')) {
                    metal.add(current);
                    current= current+4;
                }
            }
            current++;
        }

        for(int i=0; i<metal.size();i++) {
            for(int j=0;j<heavy.size();j++) {
                if(heavy.get(j)<metal.get(i)){
                    total++;
                }else {
                    break;
                }
            }
        }

        System.out.println(total);
    }

}


import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class StringsOfPower {
    public static void main(String [] args) {
        Scanner in = new Scanner(System.in) ;
        String heavymetal = in.next();
        int total =0;
        List<Integer> heavy = new ArrayList<>();
        int current = 0;

        while(current < heavymetal.length()) {
            if(current<heavymetal.length() && current+4 < heavymetal.length()) {
                if ((heavymetal.charAt(current) == 'h') && (heavymetal.charAt(current+1) == 'e') && (heavymetal.charAt(current+2) == 'a') &&
                (heavymetal.charAt(current+3) == 'v') && (heavymetal.charAt(current+4) == 'y')) {
                    heavy.add(current);
                    current= current+5;
                }else if ((heavymetal.charAt(current) == 'm') && (heavymetal.charAt(current+1) == 'e') && (heavymetal.charAt(current+2) == 't') &&
                        (heavymetal.charAt(current+3) == 'a') && (heavymetal.charAt(current+4) == 'l')) {
                    current= current+5;
                    total= total+ heavy.size();
                }else {
                    current++;
                }
            }else {
                current++;
            }
        }

        System.out.println(total);
    }

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import javafx.util.Pair;

public  class CodeForce {
static	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();

	static boolean flag = false;

	static int next(String [] sr,int ind)
	{
		return Integer.parseInt(sr[ind]);
	}

	public static void main(String[] args) throws IOException {

String sr=br.readLine();
int count=0;
int total=0;
if(sr.length()<10)
	System.out.println("0");
else
{
	for(int i=sr.length()-5;i>=0;i--)
	{
		if(sr.charAt(i)=='m')
		{
			if(sr.substring(i,i+5).equals("metal"))
				count++;
		}
		if(sr.charAt(i)=='h')
		{
			if(sr.substring(i,i+5).equals("heavy"))
				total+=count;
		}
	}
	System.out.println(total);

}

}

}


import java.io.*;
import java.math.*;
import java.security.*;
import java.text.*;
import java.util.*;
import javafx.util.Pair;

public  class CodeForce {
static	BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
static StringBuilder sb = new StringBuilder();

	static boolean flag = false;

	static int next(String [] sr,int ind)
	{
		return Integer.parseInt(sr[ind]);
	}

	public static void main(String[] args) throws IOException {

String sr=br.readLine();
long count=0;
long total=0;
if(sr.length()<10)
	System.out.println("0");
else
{
	for(int i=sr.length()-5;i>=0;i--)
	{
		if(sr.charAt(i)=='m')
		{
			if(sr.substring(i,i+5).equals("metal"))
				count++;
		}
		if(sr.charAt(i)=='h')
		{
			if(sr.substring(i,i+5).equals("heavy"))
				total+=count;
		}
	}
	System.out.println(total);

}

}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.StringTokenizer;

@SuppressWarnings("unused")
public class A {
	public  static  FastScannerA scan = new FastScannerA();
	public static PrintWriter out = new PrintWriter(System.out);

	public static void solve () {
		String s=scan.next();
		int n=s.length();
		int ans=0,a=0;
		for(int i=0;i<n-4;i++) {
			if(s.substring(i,i+5).equals("heavy")) {
				a++;
			}
			else if(s.substring(i, i+5).equals("metal")) {ans+=a;}
		}
		System.out.println(ans);
	}
	public static void main(String[] args) {

		solve();
		out.close();
	}

}
class FastScannerA {
	BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st= new StringTokenizer("");
	String next() {
		while (!st.hasMoreTokens())
			try {
				st=new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		return st.nextToken();
	}
	int nextInt() {
		return Integer.parseInt(next());
	}
	int[] readArray(int n) {
		int[] a=new int[n];
		for (int i=0; i<n; i++) a[i]=nextInt();
		return a;
	}
	long nextLong() {
		return Long.parseLong(next());
	}

}


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.StringTokenizer;

@SuppressWarnings("unused")
public class A {
	public  static  FastScannerA scan = new FastScannerA();
	public static PrintWriter out = new PrintWriter(System.out);

	public static void solve () {
		String s=scan.next();
		int n=s.length();
		long ans=0,a=0;
		for(int i=0;i<n-4;i++) {
			if(s.substring(i,i+5).equals("heavy")) {
				a++;
			}
			else if(s.substring(i, i+5).equals("metal")) {ans+=a;}
		}
		System.out.println(ans);
	}
	public static void main(String[] args) {

		solve();
		out.close();
	}

}
class FastScannerA {
	BufferedReader br= new BufferedReader(new InputStreamReader(System.in));
	StringTokenizer st= new StringTokenizer("");
	String next() {
		while (!st.hasMoreTokens())
			try {
				st=new StringTokenizer(br.readLine());
			} catch (IOException e) {
				e.printStackTrace();
			}
		return st.nextToken();
	}
	int nextInt() {
		return Integer.parseInt(next());
	}
	int[] readArray(int n) {
		int[] a=new int[n];
		for (int i=0; i<n; i++) a[i]=nextInt();
		return a;
	}
	long nextLong() {
		return Long.parseLong(next());
	}

}


import java.util.Scanner;
public class StringsOfPower {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        int count = 0 , powerCount = 0;
        for(int i = 0; i < s.length(); i++){
            if(i+5 <= s.length()){
                String sub = s.substring(i , i+5);
                if(sub.equals("heavy")) count++;
                else if(sub.equals("metal")) powerCount += count;
            }
        }
        System.out.println(powerCount);
    }
}


import java.util.Scanner;
public class StringsOfPower {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        String s = input.next();
        long count = 0 , powerCount = 0;
        for(int i = 0; i < s.length(); i++){
            if(i+5 <= s.length()){
                String sub = s.substring(i , i+5);
                if(sub.equals("heavy")) count++;
                else{
                    if(sub.equals("metal")) powerCount += count;
                }
            }
        }
        System.out.println(powerCount);
    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        String s = "", aux;
        int count = 0, indice;

        Scanner sc = new Scanner(System.in);

        try {
            s = sc.nextLine();
        } catch (NumberFormatException e) {
        }

        indice = s.indexOf("metal");
        while (indice != -1) {
            aux = s.substring(0, indice);
            count += ((aux.length() - aux.replaceAll("heavy", "").length()) / 5);
            s = s.replaceFirst("metal", "");
            indice = s.indexOf("metal");
        }

        System.out.println(count);

    }
}


import java.util.Scanner;

public class test{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
                int count =0,inc =0;

                String[] parts = s.split("heavy");
                for(int i=0;i<parts.length;i++)
                {

                      count+= ((parts[i].length() - parts[i].replaceAll("metal", "").length()) / 5)*inc;
                      inc+=1;
                }
		System.out.println(count);
	}
}


import java.util.Scanner;

public class test{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
                long count =0;

                s= s.substring(0,s.lastIndexOf("metal")+5) +".";
                String[] parts = s.split("metal");
                for(int i=0;i<parts.length;i++)
                {
                    if(i!=0 && i<parts.length-1)
                    {count*=2;}
                    count += ((parts[i].length() - parts[i].replaceAll("heavy", "").length()) / 5);

                }
		System.out.println(count);
	}
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static void main(String[] args) {

        String s="";
        Scanner sc = new Scanner(System.in);

        try {
            s= sc.nextLine();
        } catch (NumberFormatException e) {}

        int count = 0;
        String aux =s;
        while(aux.matches("(.*)heavy(.*)")){
            aux = s.substring(s.indexOf("heavy"),s.length());
        while(aux.matches("(.*)heavy(.*)metal(.*)")){
            count++;
            aux = aux.replaceFirst("metal", "");
        }
        s =s.replaceFirst("heavy", "");
        aux =s;
        }

        System.out.println(count);

    }}


package javaapplication2;

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        String s="";
        Scanner sc = new Scanner(System.in);

        try {
            s= sc.nextLine();
        } catch (NumberFormatException e) {}

        int count = 0;
        int index=-1;
        String aux="";

        index = s.indexOf("metal");
        while(index!=-1){
            aux = s.substring(0,index);
            count += (aux.length()-aux.replaceAll("heavy","").length())/5;
             s = s.replaceFirst("metal", "");
             index=s.indexOf("metal");
        }

        System.out.println(count);

    }}


import java.util.Scanner;

public class test{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
                int count =0;

                String[] parts = s.split("metal");
                for(int i=0;i<parts.length;i++)
                {
                    if(i<parts.length-1)
                        count*=i+1;
                    count += ((parts[i].length() - parts[i].replaceAll("heavy", "").length()) / 5);

                }
		System.out.println(count);
	}
}


package javaapplication2;

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        String s="";
        Scanner sc = new Scanner(System.in);

        try {
            s= sc.nextLine();
        } catch (NumberFormatException e) {}

        int count = 0;
        int index;
        String aux;

        index = s.indexOf("metal");
        while(index!=-1){
            aux = s.substring(0,index);
            count += (aux.length()-aux.replaceAll("heavy","").length())/5;
             s = s.replaceFirst("metal", "");
             index=s.indexOf("metal");
        }

        System.out.println(count);

    }}


import java.util.Scanner;

public class test{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
                int count =0;

                s= s.substring(0,s.lastIndexOf("metal")+5) +".";
                String[] parts = s.split("metal");
                for(int i=0;i<parts.length;i++)
                {
                    if(i!=0 && i<parts.length-1)
                    {count*=2;}
                    count += ((parts[i].length() - parts[i].replaceAll("heavy", "").length()) / 5);

                }
		System.out.println(count);
	}
}


package javaapplication2;

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        String s="";
        int count = 0;
        int index;
        String aux;

        Scanner sc = new Scanner(System.in);

        try {
            s= sc.nextLine();
        } catch (NumberFormatException e) {}

        index = s.indexOf("metal");

        while(index != -1){
            aux = s.substring(0,index);
            count = count + ((aux.length()-aux.replaceAll("heavy","").length())/5);
             s = s.replaceFirst("metal", "");
             index=s.indexOf("metal");
        }

        System.out.println(count);

    }}


import java.util.Scanner;

public class test{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
                long count =0,counth =0,countht=0;

                s= s.substring(0,s.lastIndexOf("metal")+5);
                String[] parts = s.split("metal");
                for(int i=0;i<parts.length;i++)
                {
                    if(counth ==1)
                    count*=2;
                    else
                      count*=countht;

                    counth = ((parts[i].length() - parts[i].replaceAll("heavy", "").length()) / 5);
                    countht+=counth;
                    count+=counth;
                }
		System.out.println(count);
	}
}


package javaapplication2;

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        String s="";
        int count = 0;
        int index;
        String aux;

        Scanner sc = new Scanner(System.in);

        try {
            s= sc.nextLine();
        } catch (NumberFormatException e) {}

        index = s.indexOf("metal");

        while(index != -1){
            aux = s.substring(0,index);
            count = count + ((aux.length()-aux.replaceAll("heavy","").length())/5);
             s = s.replaceFirst("metal", "");
             index=s.indexOf("metal");
             index=-1;
        }

        System.out.println(count);

    }}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        String s = "", aux;
        int count = 0, indice;

        Scanner sc = new Scanner(System.in);

        try {
            s = sc.nextLine();
        } catch (NumberFormatException e) {
        }

        indice = s.indexOf("metal");
        while (indice != -1) {
            aux = s.substring(0, indice);
            count = count + ((aux.length() - aux.replaceAll("heavy", "").length()) / 5);
            s = s.replaceFirst("metal", "");
            indice = s.indexOf("metal");
        }

        System.out.println(count);

    }
}


/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        String s = "", aux;
        long count = 0;
        int indice;

        Scanner sc = new Scanner(System.in);
        s = sc.nextLine();

        indice = s.indexOf("metal");
        while (indice != -1) {
            aux = s.substring(0, indice);
            count += ((aux.length() - aux.replaceAll("heavy", "").length()) / 5);
            s = s.replaceFirst("metal", "");
            indice = s.indexOf("metal");
        }

        System.out.println(count);

    }
}


package javaapplication2;

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        String s="",aux;
        int count = 0,indice;

        Scanner sc = new Scanner(System.in);

        try {
            s= sc.nextLine();
        } catch (NumberFormatException e) {}

        indice = s.indexOf("metal");
        while(indice != -1){
            aux = s.substring(0,indice);
            count = count + ((aux.length()-aux.replaceAll("heavy","").length())/5);
             s = s.replaceFirst("metal", "");
             indice=s.indexOf("metal");
        }

        System.out.println(count);

    }}


import java.util.Scanner;

public class test{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
		int heavy=0;
		long res=0;
		for (int i = 0; i <= s.length()-5; i++) {
			String temp=s.substring(i, i+5);
			if(temp.equals("heavy"))
				heavy++;
			else if(temp.equals("metal"))
				res+=heavy;
		}
		System.out.println(res);
	}
}


package javaapplication2;

import java.util.Scanner;

public class Main{

    public static void main(String[] args) {

        String s="",aux;
        int count = 0,indice;

        Scanner sc = new Scanner(System.in);

        try {
            s= sc.nextLine();
        } catch (NumberFormatException e) {}

        //indice = s.indexOf("metal");
        indice =-1;
        while(indice != -1){
            aux = s.substring(0,indice);
            count = count + ((aux.length()-aux.replaceAll("heavy","").length())/5);
             s = s.replaceFirst("metal", "");
             indice=s.indexOf("metal");
        }

        System.out.println(count);

    }}


import java.util.Scanner;

public class test{
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String s = in.nextLine();
                int count =0;

                s+=".";
                String[] parts = s.split("metal");
                for(int i=0;i<parts.length;i++)
                {   if(i!=0 && i<parts.length-1)
                    count*=2;
                    count += ((parts[i].length() - parts[i].replaceAll("heavy", "").length()) / 5);
                }
		System.out.println(count);
	}
}


// ~/BAU/ACM-ICPC/Teams/A++/BlackBurn95

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                              // (new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        String s = in.readLine();
        List<Integer> num = new ArrayList<>();

        String h = "heavy",m = "metal";
        boolean f;
        for(int i=0; i<s.length(); i++) {
            if(s.charAt(i)=='h' && i+4<s.length()) {
               f = true;
               for(int j=0; j<=4; j++)
                   if(s.charAt(i+j)!=h.charAt(j)) {
                       f = false;
                       break;
                   }
               if(f) {
                   i += 4;
                   num.add(0);
               }
            } else if(s.charAt(i)=='m' && i+4<s.length()) {
                f = true;
                for(int j=0; j<=4; j++)
                    if(s.charAt(i+j)!=m.charAt(j)) {
                        f = false;
                        break;
                    }
                if(f) {
                    i += 4;
                    num.add(1);
                }
            }
        }

        long ans = 0,cnt = 0;

        for(int i=num.size()-1; i>=0; i--) {
            if(num.get(i)==1) cnt++;
            else ans += cnt;
        }

        System.out.println(ans);
    }

}


// ~/BAU/ACM-ICPC/Teams/A++/BlackBurn95

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                              // (new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        String s = in.readLine();
        List<Integer> num = new ArrayList<>();

        String h = "heavy",m = "metal";
        boolean f;
        for(int i=0; i<s.length(); i++) {
            if(s.charAt(i)=='h' && i+4<s.length()) {
               f = true;
               for(int j=0; j<4; j++)
                   if(s.charAt(i+j)!=h.charAt(j)) {
                       f = false;
                       break;
                   }
               if(f) {
                   i += 4;
                   num.add(0);
               }
            } else if(s.charAt(i)=='m' && i+4<s.length()) {
                f = true;
                for(int j=0; j<4; j++)
                    if(s.charAt(i+j)!=m.charAt(j)) {
                        f = false;
                        break;
                    }
                if(f) {
                    i += 4;
                    num.add(1);
                }
            }
        }

        long ans = 0,cnt = 0;

        for(int i=num.size()-1; i>=0; i--) {
            if(num.get(i)==1) cnt++;
            else ans += cnt;
        }

        System.out.println(ans);
    }

}


// ~/BAU/ACM-ICPC/Teams/A++/BlackBurn95

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                              // (new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        String s = in.readLine();
        List<Integer> num = new ArrayList<>();

        String h = "heavy",m = "metal";
        boolean f;
        for(int i=0; i<s.length(); i++) {
            if(s.charAt(i)=='h' && i+4<s.length()) {
               f = true;
               for(int j=0; j<4; j++)
                   if(s.charAt(i+j)!=h.charAt(j)) {
                       f = false;
                       break;
                   }
               if(f) num.add(0);
            } else if(s.charAt(i)=='m' && i+4<s.length()) {
                f = true;
                for(int j=0; j<4; j++)
                    if(s.charAt(i+j)!=m.charAt(j)) {
                        f = false;
                        break;
                    }
                if(f) num.add(1);
            }
        }

        long ans = 0,cnt = 0;

        for(int i=num.size()-1; i>=0; i--) {
            if(num.get(i)==1) cnt++;
            else ans += cnt;
        }

        System.out.println(ans);
    }

}


// ~/BAU/ACM-ICPC/Teams/A++/BlackBurn95

import java.io.*;
import java.util.*;
import java.math.*;
import static java.lang.Math.*;
import static java.lang.Integer.parseInt;
import static java.lang.Long.parseLong;
import static java.lang.Double.parseDouble;
import static java.lang.String.*;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
                                              // (new FileReader("input.in"));
        StringBuilder out = new StringBuilder();
        StringTokenizer tk;

        String s = in.readLine();
        List<Integer> num = new ArrayList<>();

        String h = "heavy",m = "metal";
        boolean f;
        for(int i=0; i<s.length(); i++) {
            if(s.charAt(i)=='h' && i+4<s.length()) {
               f = true;
               for(int j=0; j<4; j++)
                   if(s.charAt(i+j)!=h.charAt(j)) {
                       f = false;
                       break;
                   }
               if(f) {
                   i += 5;
                   num.add(0);
               }
            } else if(s.charAt(i)=='m' && i+4<s.length()) {
                f = true;
                for(int j=0; j<4; j++)
                    if(s.charAt(i+j)!=m.charAt(j)) {
                        f = false;
                        break;
                    }
                if(f) {
                    i += 5;
                    num.add(1);
                }
            }
        }

        long ans = 0,cnt = 0;

        for(int i=num.size()-1; i>=0; i--) {
            if(num.get(i)==1) cnt++;
            else ans += cnt;
        }

        System.out.println(ans);
    }

}


import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
/* * */

public class _188_B implements Runnable{
    public static void main(String[] args) {
	    new Thread(null, new _188_B(),"Main",1<<27).start();
    }
    @Override
    public void run() {
        FastReader fd = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        String data = fd.next();
        int count = 0;
        ArrayList<Integer> heavy = new ArrayList<>();
        ArrayList<Integer> metal = new ArrayList<>();
        for(int i = 0; i < data.length(); i++){
            int ind = data.indexOf("heavy",i);
            if(ind == -1)break;
            heavy.add(ind);
            i = ind+5;
        }
        if(heavy.size() > 0){
            for(int i = 0; i < data.length(); i++){
                int ind = data.indexOf("metal",i);
                if(ind == -1)break;
                metal.add(ind);
                i = ind+5;
            }
            if(metal.size() > 0){
                int i = 0;
                while(i < heavy.size()){
                    int j = 0;
                    while(j < metal.size() && heavy.get(i) > metal.get(j)){j++;}
                    while(j < metal.size() && heavy.get(i) < metal.get(j)){count++;j++;}
                    i++;
                }
                out.println(count);
            }
            else{
                out.println(0);
            }
        }
        else{
            out.println(0);
        }
        out.close();
    }

    //Helper functions
    static int[] getArray(int n,boolean isSorted, FastReader fd){
        int[] data = new int[n];
        for(int i = 0; i < data.length; i++){ data[i] = fd.nextInt(); }
        if(isSorted) Arrays.sort(data);
        return data;
    }
    static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    static void dfs(ArrayList<ArrayList<Integer>> g, boolean[] visited, int i, int N){
        for(Integer e: g.get(i)){
            if(!visited[e]){
                visited[e]=true;
                dfs(g,visited,e,N);
                //operations to be performed...
            }
        }
    }
    static int lcm(int a, int b) {
        return (a*b)/gcd(a, b);
    }

    static boolean checkDistinct(int next){// check all digits are distinct.

        String process = String.valueOf(next);
        for(int i = 0;i < process.length()-1; i++){
            String character = String.valueOf(process.charAt(i));
            if(process.substring(i+1).contains(character)){ return false; }
        }
        return true;
    }

    static int limit = (int) 1e7 + 1;
    static int[] facts = new int[limit];
    static void sieve() {  // Store the minimum prime factors of 1 to LIMIT
        facts[1] = 1;
        for (int i = 2; i < limit; i++) {
            if (i % 2 == 0 && i > 2) {
                facts[i] = 2;
            } else {
                facts[i] = i;
            }
        }
        for (int i = 3; i * i < limit; i++) {
            if (facts[i] == i) {
                for (int j = i * i; j < limit; j += i)
                    if (facts[j] == j)
                        facts[j] = i;
            }
        }
    }
    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
/* * */

public class _188_B implements Runnable{
    public static void main(String[] args) {
	    new Thread(null, new _188_B(),"Main",1<<27).start();
    }
    @Override
    public void run() {
        FastReader fd = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        String data = fd.next();
        long count = 0,prefix = 0;
        for(int i = 0; i < data.length()-4; i++){
            if(data.substring(i,i+5).equals("heavy")){
                prefix++;i+=4;
            }
            else if(data.substring(i,i+5).equals("metal")){
                count+=prefix;i+=4;
            }
        }
        out.println(count);
        out.close();
    }

    //Helper functions
    static int[] getArray(int n,boolean isSorted, FastReader fd){
        int[] data = new int[n];
        for(int i = 0; i < data.length; i++){ data[i] = fd.nextInt(); }
        if(isSorted) Arrays.sort(data);
        return data;
    }
    static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    static void dfs(ArrayList<ArrayList<Integer>> g, boolean[] visited, int i, int N){
        for(Integer e: g.get(i)){
            if(!visited[e]){
                visited[e]=true;
                dfs(g,visited,e,N);
                //operations to be performed...
            }
        }
    }
    static int lcm(int a, int b) {
        return (a*b)/gcd(a, b);
    }

    static boolean checkDistinct(int next){// check all digits are distinct.

        String process = String.valueOf(next);
        for(int i = 0;i < process.length()-1; i++){
            String character = String.valueOf(process.charAt(i));
            if(process.substring(i+1).contains(character)){ return false; }
        }
        return true;
    }

    static int limit = (int) 1e7 + 1;
    static int[] facts = new int[limit];
    static void sieve() {  // Store the minimum prime factors of 1 to LIMIT
        facts[1] = 1;
        for (int i = 2; i < limit; i++) {
            if (i % 2 == 0 && i > 2) {
                facts[i] = 2;
            } else {
                facts[i] = i;
            }
        }
        for (int i = 3; i * i < limit; i++) {
            if (facts[i] == i) {
                for (int j = i * i; j < limit; j += i)
                    if (facts[j] == j)
                        facts[j] = i;
            }
        }
    }
    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


import java.io.*;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
/* * */

public class _188_B implements Runnable{
    public static void main(String[] args) {
	    new Thread(null, new _188_B(),"Main",1<<27).start();
    }
    @Override
    public void run() {
        FastReader fd = new FastReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        String data = fd.next();
        int count = 0,prefix = 0;
        for(int i = 0; i < data.length()-4; i++){
            if(data.substring(i,i+5).equals("heavy")){
                prefix++;i+=4;
            }
            else if(data.substring(i,i+5).equals("metal")){
                count+=prefix;i+=4;
            }
        }
        out.println(count);
        out.close();
    }

    //Helper functions
    static int[] getArray(int n,boolean isSorted, FastReader fd){
        int[] data = new int[n];
        for(int i = 0; i < data.length; i++){ data[i] = fd.nextInt(); }
        if(isSorted) Arrays.sort(data);
        return data;
    }
    static int gcd(int a, int b) {
        if (a == 0)
            return b;
        return gcd(b % a, a);
    }

    static void dfs(ArrayList<ArrayList<Integer>> g, boolean[] visited, int i, int N){
        for(Integer e: g.get(i)){
            if(!visited[e]){
                visited[e]=true;
                dfs(g,visited,e,N);
                //operations to be performed...
            }
        }
    }
    static int lcm(int a, int b) {
        return (a*b)/gcd(a, b);
    }

    static boolean checkDistinct(int next){// check all digits are distinct.

        String process = String.valueOf(next);
        for(int i = 0;i < process.length()-1; i++){
            String character = String.valueOf(process.charAt(i));
            if(process.substring(i+1).contains(character)){ return false; }
        }
        return true;
    }

    static int limit = (int) 1e7 + 1;
    static int[] facts = new int[limit];
    static void sieve() {  // Store the minimum prime factors of 1 to LIMIT
        facts[1] = 1;
        for (int i = 2; i < limit; i++) {
            if (i % 2 == 0 && i > 2) {
                facts[i] = 2;
            } else {
                facts[i] = i;
            }
        }
        for (int i = 3; i * i < limit; i++) {
            if (facts[i] == i) {
                for (int j = i * i; j < limit; j += i)
                    if (facts[j] == j)
                        facts[j] = i;
            }
        }
    }
    static class FastReader {
        private InputStream stream;
        private byte[] buf = new byte[1024];
        private int curChar;
        private int numChars;
        private SpaceCharFilter filter;
        private BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

        public FastReader(InputStream stream) {
            this.stream = stream;
        }

        public int read() {
            if (numChars==-1)
                throw new InputMismatchException();

            if (curChar >= numChars) {
                curChar = 0;
                try {
                    numChars = stream.read(buf);
                }
                catch (IOException e) {
                    throw new InputMismatchException();
                }

                if(numChars <= 0)
                    return -1;
            }
            return buf[curChar++];
        }

        public String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            }
            catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
        public int nextInt() {
            int c = read();

            while(isSpaceChar(c))
                c = read();

            int sgn = 1;

            if (c == '-') {
                sgn = -1;
                c = read();
            }

            int res = 0;
            do {
                if(c<'0'||c>'9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));

            return res * sgn;
        }

        public long nextLong() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            long res = 0;

            do {
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            while (!isSpaceChar(c));
            return res * sgn;
        }

        public double nextDouble() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            int sgn = 1;
            if (c == '-') {
                sgn = -1;
                c = read();
            }
            double res = 0;
            while (!isSpaceChar(c) && c != '.') {
                if (c == 'e' || c == 'E')
                    return res * Math.pow(10, nextInt());
                if (c < '0' || c > '9')
                    throw new InputMismatchException();
                res *= 10;
                res += c - '0';
                c = read();
            }
            if (c == '.') {
                c = read();
                double m = 1;
                while (!isSpaceChar(c)) {
                    if (c == 'e' || c == 'E')
                        return res * Math.pow(10, nextInt());
                    if (c < '0' || c > '9')
                        throw new InputMismatchException();
                    m /= 10;
                    res += (c - '0') * m;
                    c = read();
                }
            }
            return res * sgn;
        }

        public String readString() {
            int c = read();
            while (isSpaceChar(c))
                c = read();
            StringBuilder res = new StringBuilder();
            do {
                res.appendCodePoint(c);
                c = read();
            }
            while (!isSpaceChar(c));

            return res.toString();
        }

        public boolean isSpaceChar(int c) {
            if (filter != null)
                return filter.isSpaceChar(c);
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public String next() {
            return readString();
        }

        public interface SpaceCharFilter {
            public boolean isSpaceChar(int ch);
        }
    }
}


/***
 *    ██████╗=====███████╗====███████╗====██████╗=
 *    ██╔══██╗====██╔════╝====██╔════╝====██╔══██╗
 *    ██║==██║====█████╗======█████╗======██████╔╝
 *    ██║==██║====██╔══╝======██╔══╝======██╔═══╝=
 *    ██████╔╝====███████╗====███████╗====██║=====
 *    ╚═════╝=====╚══════╝====╚══════╝====╚═╝=====
 *    ============================================
 */

import sun.nio.cs.KOI8_U;

import java.io.*;
import java.util.*;
import java.math.*;
import java.lang.*;

public class AD implements Runnable {

    public void run() {
        InputReader sc = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int i=0,j=0,k=0;
        int t=0;
        //t=sc.nextInt();
        for(int testcase = 0; testcase < t; testcase++)
        {
        }

        String str=sc.next();
        String heavy="heavy";
        String metal="metal";

        int strlen=str.length();
        List<Integer> hli=new ArrayList<>();
        List<Integer> mli=new ArrayList<>();
        for (i=0;i<strlen-4;i++)
        {
            String temp=str.substring(i,i+5);
            //out.println(str.substring(i,i+5));
            if (temp.equals(heavy))
            {
                hli.add(i);
            }
            else if (temp.equals(metal))
            {
                mli.add(i);
            }
        }

        i=0;
        j=0;
        int hlisize=hli.size();
        int mlisize=mli.size();
        long ans=0;

        while (i<hlisize&&j<mlisize)
        {
            while (j<mlisize&&hli.get(i)>mli.get(j))
                j++;
            ans+=mlisize-j;
            i++;
        }
        out.println(ans);
//================================================================================================================================
        out.flush();
        out.close();
    }

    //================================================================================================================================
    public static int[] sa(int n,InputReader sc)
    {
        int arr[]=new int[n];
        for (int i=0;i<n;i++)
            arr[i]=sc.nextInt();
        return arr;
    }
    public static long gcd(long a,long b){
        return (a%b==0l)?b:gcd(b,a%b);
    }
    private static long lcm(long a, long b)
    {
        return a * (b / gcd(a, b));
    }
    public int egcd(int a, int b) {
        if (a == 0)
            return b;

        while (b != 0) {
            if (a > b)
                a = a - b;
            else
                b = b - a;
        }

        return a;
    }

    public int countChar(String str, char c)
    {
        int count = 0;
        for(int i=0; i < str.length(); i++)
        {    if(str.charAt(i) == c)
            count++;
        }
        return count;
    }
    static int binSearch(Integer[] arr, int number){
        int left=0,right=arr.length-1,mid=(left+right)/2,ind=0;
        while(left<=right){
            if(arr[mid]<=number){
                ind=mid+1;
                left=mid+1;
            }
            else
                right=mid-1;
            mid=(left+right)/2;
        }
        return ind;
    }
    static int binSearch(int[] arr, int number){
        int left=0,right=arr.length-1,mid=(left+right)/2,ind=0;
        while(left<=right){
            if(arr[mid]<=number){
                ind=mid+1;
                left=mid+1;
            }
            else
                right=mid-1;
            mid=(left+right)/2;
        }
        return ind;
    }
    static class Pair
    {
        int a,b;
        Pair(int aa,int bb)
        {
            a=aa;
            b=bb;
        }
        String get()
        {
            return a+" "+b;
        }
        String getrev()
        {
            return b+" "+a;
        }
    }

    static boolean isPrime(long n) {
        if(n < 2) return false;
        if(n == 2 || n == 3) return true;
        if(n%2 == 0 || n%3 == 0) return false;
        long sqrtN = (long)Math.sqrt(n)+1;
        for(long i = 6L; i <= sqrtN; i += 6) {
            if(n%(i-1) == 0 || n%(i+1) == 0) return false;
        }
        return true;
    }
    static long factorial(long n)
    {
        if (n == 0)
            return 1;
        return n*factorial(n-1);
    }
//================================================================================================================================

    static class InputReader
    {
        BufferedReader br;
        StringTokenizer st;

        public InputReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main(String args[]) throws Exception {
        new Thread(null, new AD(),"Main",1<<27).start();
    }
}