#include <bits/stdc++.h>

//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int inf = 1e9, maxn = 1e7 + 48, mod = 1e9 + 7, N = 2e5 + 104;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, v, u, res[N], timer, ans, m, was[2][N];
vi g[2][N];

void dfs (int v, int j) {
	was[j][v] = timer;
	for (auto to : g[j][v]) {
		if (was[j][to] == timer) {
		    cout << -1;
		    exit(0);
		}

		if (!was[j][to])
			dfs(to, j);
	}

}

main () {
	cin >> n >> m;
	while (m--) {
		cin >> v >> u;
		g[0][v].pb(u);
		g[1][u].pb(v);
	}

	for (int i = 1; i <= n; ++i) {
	    if (!was[0][i] && !was[1][i]) {
			res[i] = 1;
			++ans;
		}

		++timer;
		if (!was[0][i])
			dfs(i, 0);
		if (!was[1][i])
			dfs(i, 1);
	}

	cout << ans << endl;
	for (int i = 1; i <= n; ++i)
		cout << (res[i] ? 'A' : 'E');

}


#include <bits/stdc++.h>

#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int inf = 1e9, maxn = 1e7 + 48, mod = 1e9 + 7, N = 2e5 + 104;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, v, u, res[N], timer, ans, m;
bool was[2][N];
vi g[2][N];

void dfs (int v, int j) {
	was[j][v] = timer;
	for (auto to : g[j][v]) {
		if (was[j][to] == timer) {
		    cout << -1;
		    exit(0);
		}

		if (!was[j][to])
			dfs(to, j);
	}

}

main () {
	cin >> n >> m;
	while (m--) {
		cin >> v >> u;
		g[0][v].pb(u);
		g[1][u].pb(v);
	}

	for (int i = 1; i <= n; ++i) {
	    if (!was[0][i] && !was[1][i]) {
			res[i] = 1;
			++ans;
		}

		++timer;
		if (!was[0][i])
			dfs(i, 0);
		if (!was[1][i])
			dfs(i, 1);
	}

	cout << ans << endl;
	for (int i = 1; i <= n; ++i)
		cout << (res[i] ? 'A' : 'E');

}


#include <bits/stdc++.h>

#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int inf = 1e9, maxn = 1e7 + 48, mod = 1e9 + 7, N = 1e5 + 104;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, v, u, res[N], timer, ans, m;
bool was[2][N];
vi g[2][N];

void dfs (int v, int j) {
	was[j][v] = timer;
	for (auto to : g[j][v]) {
		if (was[j][to] == timer) {
		    cout << -1;
		    exit(0);
		}

		if (!was[j][to])
			dfs(to, j);
	}

}

main () {
	cin >> n >> m;
	while (m--) {
		cin >> v >> u;
		g[0][v].pb(u);
		g[1][u].pb(v);
	}

	for (int i = 1; i <= n; ++i) {
		if (was[0][i] || was[1][i])
			continue;
		++timer;
		dfs(i, 0);
		dfs(i, 1);
		res[i] = 1;
		++ans;
	}

	cout << ans << endl;
	for (int i = 1; i <= n; ++i)
		cout << (res[i] ? 'A' : 'E');

}


#include <bits/stdc++.h>

//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int inf = 1e9, maxn = 2e3 + 48, mod = 1e9 + 7, N = 2e5 + 24;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, m, v, u, was[N], timer, cnt[N];
vi g[N];

void dfs (int v) {
	was[v] = timer;
	for (auto to : g[v])
		if (!was[to])
			dfs(to);
		else if (was[to] == timer) {
			cout << -1;
			exit(0);
		}
}

main () {
	cin >> n >> m;
	while (m--) {
		cin >> v >> u;
		g[v].pb(u);
		++cnt[u];
	}

	for (int i = 1; i <= n; ++i)
		if (!was[i]) {
			++timer;
			dfs(i);
		}

	int res = 0;
	string ans = "";
	for (int i = 1; i <= n; ++i)
		if (!cnt[i]) {
			ans += 'A';
			++res;
		} else
			ans += 'E';

	cout << res << endl;
	cout << ans << endl;
}


#include <bits/stdc++.h>

//#define int long long
//#pragma GCC optimize("Ofast")
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define all(x) x.begin(), x.end()
#define sz(s) (int)s.size()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define s second
#define f first

using namespace std;

typedef pair < long long, long long > pll;
typedef pair < int, int > pii;
typedef unsigned long long ull;
typedef vector < pii > vpii;
typedef vector < int > vi;
typedef long double ldb;
typedef long long ll;
typedef double db;

const int inf = 1e9, maxn = 1e7 + 48, mod = 1e9 + 7, N = 2e5 + 104;
const int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1}, block = 555;
const pii base = mp(1171, 3307), Mod = mp(1e9 + 7, 1e9 + 9);
const db eps = 1e-12, pi = 3.14159265359;
const ll INF = 1e18;

int n, v, u, res[N], ans, m, was[2][N];
vi g[2][N];

void dfs (int v, int j) {
	was[j][v] = 1;
	for (auto to : g[j][v]) {
		if (was[j][to] == 1) {
		    cout << -1;
		    exit(0);
		}

		if (!was[j][to])
			dfs(to, j);
	}
 	was[j][v] = 2;
}

main () {
	cin >> n >> m;
	while (m--) {
		cin >> v >> u;
		g[0][v].pb(u);
		g[1][u].pb(v);
	}

	for (int i = 1; i <= n; ++i) {
	    if (!was[0][i] && !was[1][i]) {
			res[i] = 1;
			++ans;
		}

		if (!was[0][i])
			dfs(i, 0);
		if (!was[1][i])
			dfs(i, 1);
	}

	cout << ans << endl;
	for (int i = 1; i <= n; ++i)
		cout << (res[i] ? 'A' : 'E');

}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 2e5+5;
bool ok[MX];
vi edges[MX];
vi redges[MX];
bool vis1[MX], vis2[MX];
void dfs1(int v) {
    trav(u, edges[v]) {
        if (!vis1[u]) {
            vis1[u] = 1;
            dfs1(u);
        }
    }
}
void dfs2(int v) {
    trav(u, redges[v]) {
        if (!vis2[u]) {
            vis2[u] = 1;
            dfs2(u);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;

    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    F0R(i, n+1) ok[i] = 1;
    F0R(i, m) {
        cin >> j >> k;
        inCount[k]++;
        edges[j].pb(k);
        redges[k].pb(j);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    int ans = 0;
    string str = "";
    FOR(i, 1, n) {
        if(!vis1[i] && !vis2[i])ans++, str += 'A';
        else str += 'E';
        vis1[i] = vis2[i] = 1;
        dfs1(i);
        dfs2(i);
    }
    assert(ans);
    cout << ans << nl << str << nl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 2e5+5;
bool ok[MX];
vi edges[MX];
bool vis[MX];
void dfs(int v) {
    // cout << v << nl;
    trav(u, edges[v]) {
        if (!vis[u]) {
            ok[u] = 0;
            dfs(u);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;

    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    F0R(i, n+1) ok[i] = 1;
    F0R(i, m) {
        cin >> j >> k;
        ok[max(j, k)] = 0;
        inCount[k]++;
        edges[j].pb(k);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    FOR(i, 1, n) {
        if (ok[i] && !vis[i]) {
            dfs(i);
        }
    }
    int ans = 0;
    string str = "";
    FOR(i, 1, n) if (ok[i]) {
        ans++;
        str += 'A';
    } else str += 'E';
    assert(ans);
    cout << ans << nl << str << nl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 2e5+5;
bool ok[MX];
vi edges[MX];
bool vis[MX];
void dfs(int v) {
    // cout << v << nl;
    trav(u, edges[v]) {
        ok[u] = 0;
        dfs(u);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;

    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    F0R(i, n+1) ok[i] = 1;
    F0R(i, m) {
        cin >> j >> k;
        inCount[k]++;
        edges[j].pb(k);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    FOR(i, 1, n) dfs(i);
    int ans = 0;
    string str = "";
    FOR(i, 1, n) if (ok[i]) {
        ans++;
        str += 'A';
    } else str += 'E';
    assert(ans);
    cout << ans << nl << str << nl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 2e5+5;
bool ok[MX];
vi edges[MX];
vi redges[MX];
bool vis1[MX], vis2[MX];
void dfs1(int v) {
    trav(u, edges[v]) {
        if (!vis1[u]) {
            vis1[u] = 1;
            dfs1(u);
        }
    }
}
void dfs2(int v) {
    trav(u, redges[v]) {
        if (!vis2[u]) {
            vis2[u] = 1;
            dfs2(u);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;

    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    F0R(i, n+1) ok[i] = 1;
    F0R(i, m) {
        cin >> j >> k;
        inCount[k]++;
        edges[j].pb(k);
        redges[k].pb(j);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    int ans = 0;
    string str = "";
    FOR(i, 1, n) {
        if(!vis1[i] && !vis2[i])ans++, str += 'A';
        else str += 'E';
        dfs1(i);
        dfs2(i);
    }
    assert(ans);
    cout << ans << nl << str << nl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 2e5+5;
bool ok[MX];
vi edges[MX];
bool vis[MX];
void dfs(int v) {
    trav(u, edges[v]) {
        if (!vis[u]) {
            vis[u] = 1;
            ok[u] = 0;
            dfs(u);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;

    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    F0R(i, n+1) ok[i] = 1;
    F0R(i, m) {
        cin >> j >> k;
        ok[max(j, k)] = 0;
        inCount[k]++;
        edges[j].pb(k);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    FOR(i, 1, n) {
        if (ok[i] && !vis[i]) {
            vis[i] = 1;
            dfs(i);
        }
    }
    int ans = 0;
    string str = "";
    FOR(i, 1, n) if (ok[i]) {
        ans++;
        str += 'A';
    } else str += 'E';
    assert(ans);
    cout << ans << nl << str << nl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 1<<20;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;
    vi edges[n+1];
    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    bool ok[n+1]; F0R(i, n+1) ok[i] = 1;
    F0R(i, m) {
        cin >> j >> k;
        ok[max(j, k)] = 0;
        inCount[k]++;
        edges[j].pb(k);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    int ans = 0;
    string str = "";
    FOR(i, 1, n) if (ok[i]) {
        ans++;
        str += 'A';
    } else str += 'E';
    cout << ans << nl << str << nl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 2e5+5;
bool ok[MX];
vi edges[MX];
vi redges[MX];
bool vis[MX];
void dfs1(int v) {
    trav(u, edges[v]) {
        if (!vis[u]) {
            vis[u] = 1;
            dfs1(u);
        }
    }
}
void dfs2(int v) {
    trav(u, redges[v]) {
        if (!vis[u]) {
            vis[u] = 1;
            dfs2(u);
        }
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;

    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    F0R(i, n+1) ok[i] = 1;
    F0R(i, m) {
        cin >> j >> k;
        inCount[k]++;
        edges[j].pb(k);
        redges[k].pb(j);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    int ans = 0;
    string str = "";
    FOR(i, 1, n) if (!vis[i]) {
        dfs1(i);
        dfs2(i);
        ans++;
        str += 'A';
    } else str += 'E';
    assert(ans);
    cout << ans << nl << str << nl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 1<<20;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;
    vi edges[n+1];
    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    F0R(i, m) {
        cin >> j >> k;
        inCount[k]++;
        edges[j].pb(k);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    string str = "";
    FOR(i, 1, n) if (!inCount[i]) str += 'A'; else str += 'E';
    int ans = sz(zeros);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    cout << ans << nl << str << nl;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <complex>
#include <iterator>
#include <regex>
#include <fstream>
#include <utility>
#include <vector>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <chrono>
#include <cassert>

using namespace std;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define F0R(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i <= b; i++)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define FORd(i,a,b) for (int i = (b); i >= (a); i--)
#define trav(a, x) for (auto& a : x)

#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(x) (int)x.size()

const char nl = '\n';
const int MAX_N = 100011;
const ll INF = (1<<29) + 123;
const ll MOD = 1000000007; // 998244353
const ld PI = 4*atan((ld)1);

template <typename T> bool ckmin(T& a, const T& b) {
    return a > b ? a=b, 1 : 0;
}
template <typename T> bool ckmax(T& a, const T& b) {
    return b > a ? a=b, 1 : 0;
}

mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
const int MX = 2e5+5;
bool ok[MX];
vi edges[MX];
bool vis[MX];
void dfs(int v) {
    // cout << v << nl;
    trav(u, edges[v]) {
        ok[u] = 0;
        dfs(u);
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int n, m; cin >> n >> m;

    int j, k;
    queue<int> zeros;
    int inCount[n+1]; F0R(i, n+1) inCount[i] = 0;
    F0R(i, n+1) ok[i] = 1;
    F0R(i, m) {
        cin >> j >> k;
        ok[max(j, k)] = 0;
        inCount[k]++;
        edges[j].pb(k);
    }
    FOR(i, 1, n) if (!inCount[i]) zeros.push(i);
    //top sort
    int c = 0;
    while (!zeros.empty()) {
        int v = zeros.front(); zeros.pop();
        c++;
        trav(u, edges[v]) {
            inCount[u]--;
            if (!inCount[u]) zeros.push(u);
        }
    }
    if (c != n) {
        cout << -1 << nl;
        return 0;
    }
    FOR(i, 1, n) {
        dfs(i);
    }
    int ans = 0;
    string str = "";
    FOR(i, 1, n) if (ok[i]) {
        ans++;
        str += 'A';
    } else str += 'E';
    assert(ans);
    cout << ans << nl << str << nl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

void solve(int TestCase) {
    int node_cnt, edge_cnt;
    scanf("%d %d", &node_cnt, &edge_cnt);

    auto edges = vector<vector<int>>(node_cnt, vector<int>());
    for(auto i = 0; i < edge_cnt; ++i)
    {
        int u, v;
        scanf("%d %d", &u, &v);
        u--, v--;

        edges[u].push_back(v);
    }

    auto min_idx_of_child = vector<int>(node_cnt);
    auto min_idx_of_ancestor = vector<int>(node_cnt);
    for(auto i = 0; i < node_cnt; ++i) {
        min_idx_of_child[i] = i;
        min_idx_of_ancestor[i] = i;
    }

    auto visited = vector<int>(node_cnt);
    for(auto i = 0; i < node_cnt; ++i)
    {
        if(visited[i]) continue;
        auto stack_ = vector<int>();
        stack_.push_back(i);
        auto parent = vector<int>();
        parent.push_back(-1);
        while(!stack_.empty()) {
            auto node = stack_.back();
            if(visited[node]) {
                stack_.pop_back();
                parent.pop_back();
                if(visited[node] == 2)
                    continue;

                visited[node] = 2;
                for(auto& x : edges[node])
                {
                    auto idx = min_idx_of_child[x];
                    min_idx_of_child[node] = min(min_idx_of_child[node], idx);
                }
                continue;
            }

            visited[node] = 1;
            if(parent.back() != -1)
                min_idx_of_ancestor[node] =
                    min(min_idx_of_ancestor[node], min_idx_of_ancestor[parent.back()]);

            for(auto& x : edges[node])
            {
                if(visited[x] == 0)
                {
                    stack_.push_back(x);
                    parent.push_back(node);
                }
                else if(visited[x] == 1) {
                    printf("-1\n");
                    return;
                }
            }
        }
    }

    auto ret = string(node_cnt, 'E');
    auto a_cnt = 0;
    for(auto i = 0; i < node_cnt; ++i)
    {
        if(min_idx_of_ancestor[i] == i &&
            min_idx_of_child[i] == i)
        {
            ret[i] = 'A';
            a_cnt++;
        }
    }

    printf("%d\n", a_cnt);
    printf("%s\n", ret.data());
}

int main(){/*
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}


#include<bits/stdc++.h>

using namespace std;

void solve(int TestCase) {
    int node_cnt, edge_cnt;
    cin >> node_cnt >> edge_cnt;

    auto indegree = vector<int>(node_cnt);
    auto outdegree = vector<int>(node_cnt);

    auto edges = vector<vector<int>>(node_cnt, vector<int>());
    auto edges2 = vector<vector<int>>(node_cnt, vector<int>());

    for(auto i = 0; i < edge_cnt; ++i)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;

        edges2[u].push_back(v);

        if(u > v)
            swap(u, v);

        edges[u].push_back(v);
        outdegree[u]++;
        indegree[v]++;
    }

    auto visited = vector<int>(node_cnt);
    for(auto i = 0; i < node_cnt; ++i)
    {
        if(visited[i]) continue;

        auto stack_ = vector<int>();
        stack_.emplace_back(i);
        while(!stack_.empty()) {
            auto node = stack_.back();
            if(visited[node]) {
                stack_.pop_back();
                visited[node] = 2;
                continue;
            }
            visited[node] = 1;
            for(auto& x : edges2[node])
            {
                if(visited[x] == 1) {
                    cout << -1 << endl;
                    return;
                }
                else if(!visited[x])
                {
                    stack_.emplace_back(x);
                }
            }
        }
    }

    auto ret = string(node_cnt, 'E');
    auto a_cnt = 0;
    for(auto i = 0; i < node_cnt; ++i)
    {
        if(indegree[i] == 0) {
            ret[i] = 'A';
            a_cnt++;
        }
    }

    cout << a_cnt << endl;
    cout << ret << endl;
}

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

    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}


#include<bits/stdc++.h>

using namespace std;

void solve(int TestCase) {
    int node_cnt, edge_cnt;
    cin >> node_cnt >> edge_cnt;

    auto edges = vector<vector<int>>(node_cnt, vector<int>());
    for(auto i = 0; i < edge_cnt; ++i)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;

        edges[u].push_back(v);
    }

    auto min_idx_of_child = vector<int>(node_cnt);
    auto min_idx_of_ancestor = vector<int>(node_cnt);
    for(auto i = 0; i < node_cnt; ++i) {
        min_idx_of_child[i] = i;
        min_idx_of_ancestor[i] = i;
    }

    auto visited = vector<int>(node_cnt);
    for(auto i = 0; i < node_cnt; ++i)
    {
        if(visited[i]) continue;
        auto stack_ = vector<int>();
        stack_.emplace_back(i);
        auto parent = vector<int>();
        parent.emplace_back(-1);
        while(!stack_.empty()) {
            auto node = stack_.back();
            if(visited[node]) {
                stack_.pop_back();
                parent.pop_back();
                visited[node] = 2;
                for(auto& x : edges[node])
                {
                    auto idx = min_idx_of_child[x];
                    min_idx_of_child[node] = min(min_idx_of_child[node], idx);
                }
                continue;
            }

            visited[node] = 1;
            if(parent.back() != -1)
                min_idx_of_ancestor[node] =
                    min(min_idx_of_ancestor[node], min_idx_of_ancestor[parent.back()]);

            for(auto& x : edges[node])
            {
                if(visited[x] == 0)
                {
                    stack_.emplace_back(x);
                    parent.emplace_back(node);
                }
                else if(visited[x] == 1) {
                    cout << -1 << endl;
                    return;
                }
            }
        }
    }

    auto ret = string(node_cnt, 'E');
    auto a_cnt = 0;
    for(auto i = 0; i < node_cnt; ++i)
    {
        if(min_idx_of_ancestor[i] == i &&
            min_idx_of_child[i] == i)
        {
            ret[i] = 'A';
            a_cnt++;
        }
    }

    cout << a_cnt << endl;
    cout << ret << endl;
}

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

    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}


#include<bits/stdc++.h>

using namespace std;

template <typename CostType>
class graph {
public:
    struct edge {
        int from;
        int to;
        CostType cost;
    };

    vector<vector<int>> nodes;
    vector<edge> edges;

    graph(int node_cnt_)
    : nodes(node_cnt_)
    {}

    int get_node_cnt() { return nodes.size(); }
    int get_edges_cnt() { return edges.size(); }

    virtual int add(int from, int to, CostType cost) = 0;
};

template <typename CostType>
class digraph : public graph<CostType> {
public:
    using graph<CostType>::nodes;
    using graph<CostType>::edges;
    using graph<CostType>::get_node_cnt;
    using graph<CostType>::get_edges_cnt;

    digraph(int node_cnt_) : graph<CostType>(node_cnt_) {}
    int add(int from, int to, CostType cost = 1) {
        assert(0 <= from && from < get_node_cnt());
        assert(0 <= to && to < get_node_cnt());

        auto edge_idx = get_edges_cnt();
        nodes[from].push_back(edge_idx);
        edges.push_back({from, to, cost});
        return edge_idx;
    }

    digraph<CostType> get_reverse_digraph() {
        auto ret = digraph<CostType>(get_node_cnt());
        for(auto& e : edges)
            ret.add(e.to, e.from, e.cost);

        return ret;
    }
};

template <typename CostType>
vector<int> get_topsort(digraph<CostType> &g) {
    vector<int> in_degree(g.get_node_cnt());
    for (auto& e : g.edges)
        in_degree[e.to]++;

    vector<int> ret;
    for (int i = 0; i < g.get_node_cnt(); i++) {
        if (in_degree[i] == 0)
            ret.push_back(i);
    }

    for(auto i = 0; i < ret.size(); ++i)
    {
        int cur = ret[i];
        for(auto edge_idx : g.nodes[cur]) {
            auto& e = g.edges[edge_idx];
            if(--in_degree[e.to] == 0)
                ret.push_back(e.to);
        }
    }

    // invalid - cycle
    if(ret.size() != g.get_node_cnt())
       return {};

    return ret;
}

void solve(int TestCase) {
    int node_cnt, edge_cnt;
    cin >> node_cnt >> edge_cnt;

    digraph<int> g(node_cnt);
    for(auto i = 0; i < edge_cnt; ++i)
    {
        int u, v;
        cin >> u >> v;
        u--, v--;
        g.add(u, v);
    }

    auto sorted = get_topsort(g);
    if(sorted.empty()) {
        cout << -1 << endl;
        return;
    }

    auto min_idxs_left = vector<int>(node_cnt);
    auto min_idxs_right = vector<int>(node_cnt);
    iota(min_idxs_left.begin(), min_idxs_left.end(), 0);
    iota(min_idxs_right.begin(), min_idxs_right.end(), 0);
    for(auto i = 0; i < sorted.size(); ++i)
    {
        auto cur = sorted[i];
        for(auto j = 0; j < g.nodes[cur].size(); ++j)
        {
            auto edge_idx = g.nodes[cur][j];
            auto nxt = g.edges[edge_idx].to;
            min_idxs_left[nxt] = min(min_idxs_left[nxt], min_idxs_left[cur]);
        }
    }

    for(auto i = (int) sorted.size() - 1; i >= 0; --i)
    {
        auto cur = sorted[i];
        for(auto j = 0; j < g.nodes[cur].size(); ++j)
        {
            auto edge_idx = g.nodes[cur][j];
            auto nxt = g.edges[edge_idx].to;
            min_idxs_right[cur] = min(min_idxs_right[nxt], min_idxs_right[cur]);
        }
    }

    auto ret = string(node_cnt, 'E');
    int a_cnt = 0;
    for(auto i = 0; i < ret.size(); ++i)
    {
        if(min_idxs_left[i] == i && min_idxs_right[i] == i) {
            ret[i] = 'A';
            a_cnt++;
        }
    }

    cout << a_cnt << endl << ret << endl;
}

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

    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}


#include<bits/stdc++.h>

using namespace std;

void solve(int TestCase) {
    int node_cnt, edge_cnt;
    scanf("%d %d", &node_cnt, &edge_cnt);

    auto edges = vector<vector<int>>(node_cnt, vector<int>());
    for(auto i = 0; i < edge_cnt; ++i)
    {
        int u, v;
        scanf("%d %d", &u, &v);
        u--, v--;

        edges[u].push_back(v);
    }

    auto min_idx_of_child = vector<int>(node_cnt);
    auto min_idx_of_ancestor = vector<int>(node_cnt);
    for(auto i = 0; i < node_cnt; ++i) {
        min_idx_of_child[i] = i;
        min_idx_of_ancestor[i] = i;
    }

    auto visited = vector<int>(node_cnt);
    for(auto i = 0; i < node_cnt; ++i)
    {
        if(visited[i]) continue;
        auto stack_ = vector<int>();
        stack_.emplace_back(i);
        auto parent = vector<int>();
        parent.emplace_back(-1);
        while(!stack_.empty()) {
            auto node = stack_.back();
            if(visited[node]) {
                stack_.pop_back();
                parent.pop_back();
                visited[node] = 2;
                for(auto& x : edges[node])
                {
                    auto idx = min_idx_of_child[x];
                    min_idx_of_child[node] = min(min_idx_of_child[node], idx);
                }
                continue;
            }

            visited[node] = 1;
            if(parent.back() != -1)
                min_idx_of_ancestor[node] =
                    min(min_idx_of_ancestor[node], min_idx_of_ancestor[parent.back()]);

            for(auto& x : edges[node])
            {
                if(visited[x] == 0)
                {
                    stack_.emplace_back(x);
                    parent.emplace_back(node);
                }
                else if(visited[x] == 1) {
                    printf("-1\n");
                    return;
                }
            }
        }
    }

    auto ret = string(node_cnt, 'E');
    auto a_cnt = 0;
    for(auto i = 0; i < node_cnt; ++i)
    {
        if(min_idx_of_ancestor[i] == i &&
            min_idx_of_child[i] == i)
        {
            ret[i] = 'A';
            a_cnt++;
        }
    }

    printf("%d\n", a_cnt);
    printf("%s\n", ret.data());
}

int main(){/*
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);*/

    int t = 1;
    //cin >> t;
    for(auto i = 1; i <= t; ++i) {
        //cout << "Case #"<< i << ": ";
        solve(i);
    }
}


#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int maxn = 2e5 + 3;

int n, m;
vector <int> adj[maxn], rev_adj[maxn];
int deg[maxn];
void read()
{
	cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
		int a, b;
		cin >> a >> b;

		adj[a].push_back(b);
		rev_adj[b].push_back(a);

		deg[b]++;
	}
}

int min_idx[maxn];

void dfs(int ver)
{
	if (min_idx[ver] != -1)
	return;

	min_idx[ver] = ver;
	for (auto i: rev_adj[ver])
	{
		dfs(i);
		min_idx[ver] = min(min_idx[ver], min_idx[i]);
	}
}

void solve()
{
	int cnt_trav = 0;
	queue <int> q;

	for (int i = 1; i <= n; i++)
	if (deg[i] == 0)
		q.push(i);

	while (!q.empty())
	{
		int curr = q.front();
		q.pop();
		cnt_trav++;

		for (auto i: adj[curr])
		{
			deg[i]--;

			if (deg[i] == 0)
			q.push(i);
		}
	}

	if (cnt_trav != n)
	{
		cout << -1 << endl;
		return;
	}

	memset(min_idx, -1, sizeof(min_idx));
	for (int i = 1; i <= n; i++)
	dfs(i);

	vector <char> ans;
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (min_idx[i] < i)
			ans.push_back('E');

		else
		{
			ans.push_back('A');
			cnt++;
		}
	}

	cout << cnt << endl;
	for (auto i: ans)
	cout << i;

	cout << endl;
}

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

	read();
	solve();
}


#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int maxn = 2e5 + 3;

int n, m;
vector <int> adj[maxn], rev_adj[maxn];
int deg[maxn];
void read()
{
	cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
		int a, b;
		cin >> a >> b;

		adj[a].push_back(b);
		rev_adj[b].push_back(a);

		deg[b]++;
	}
}

bool used1[maxn], used2[maxn];

void dfs1(int ver)
{
	used1[ver] = true;
	for (auto i: adj[ver])
	if (!used1[i])
	dfs1(i);
}

void dfs2(int ver)
{
	if (!used1[ver])
	dfs1(ver);

	used2[ver] = true;
	for (auto i: rev_adj[ver])
	if (!used2[i])
		dfs2(i);
}

void solve()
{
	int cnt_trav = 0;
	queue <int> q;

	for (int i = 1; i <= n; i++)
	if (deg[i] == 0)
		q.push(i);

	while (!q.empty())
	{
		int curr = q.front();
		q.pop();
		cnt_trav++;

		for (auto i: adj[curr])
		{
			deg[i]--;

			if (deg[i] == 0)
			q.push(i);
		}
	}

	if (cnt_trav != n)
	{
		cout << -1 << endl;
		return;
	}

	vector <char> ans;
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (used1[i] || used2[i])
		{
			ans.push_back('E');
			continue;
		}

		cnt++;
		ans.push_back('A');

		dfs2(i);
	}

	cout << cnt << endl;
	for (auto i: ans)
	cout << i;

	cout << endl;
}

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

	read();
	solve();
}


#include <bits/stdc++.h>
#define endl '\n'

using namespace std;

const int maxn = 2e5 + 3;

int n, m;
vector <int> adj[maxn], rev_adj[maxn];
int deg[maxn];
void read()
{
	cin >> n >> m;
    for (int i = 1; i <= m; i++)
    {
		int a, b;
		cin >> a >> b;

		adj[a].push_back(b);
		rev_adj[b].push_back(a);

		deg[b]++;
	}
}

bool used1[maxn], used2[maxn];

void dfs1(int ver)
{
	used1[ver] = true;
	for (auto i: adj[ver])
	if (!used1[i])
	dfs1(i);
}

void dfs2(int ver)
{
	used2[ver] = true;
	for (auto i: rev_adj[ver])
	if (!used2[i])
	dfs2(i);
}

void solve()
{
	int cnt_trav = 0;
	queue <int> q;

	for (int i = 1; i <= n; i++)
	if (deg[i] == 0)
		q.push(i);

	while (!q.empty())
	{
		int curr = q.front();
		q.pop();
		cnt_trav++;

		for (auto i: adj[curr])
		{
			deg[i]--;

			if (deg[i] == 0)
			q.push(i);
		}
	}

	if (cnt_trav != n)
	{
		cout << -1 << endl;
		return;
	}

	vector <char> ans;
	int cnt = 0;
	for (int i = 1; i <= n; i++)
	{
		if (used1[i] || used2[i])
		{
			ans.push_back('E');
			continue;
		}

		cnt++;
		ans.push_back('A');

		dfs1(i);
		dfs2(i);
	}

	cout << cnt << endl;
	for (auto i: ans)
	cout << i;

	cout << endl;
}

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

	read();
	solve();
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (int)1e9
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);

int n ,k;
string a = "abcdefghijklmnopqrstuvwxyz";
int main()
{
    string s;
    cin >> n >> k;
    cin >> s;
    int len = 1, can = 0;
    for(int i = 0   ; i < n; ++i)
    {
        int cnt = 1;
        if(s[i] == 'A')
        {
            char last = s[i];

            for(int j = i + 1; j < n ; ++j)
            {

                if(s[j] == char(k + 'A' - 1)) can = 1;
                if(s[j] - last == 1   || s[j] - last == 0)
                    last = s[j],len++;

            }
            break;
        }
    }
    if(can)cout << len;
    else cout << 0;

return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (int)1e9
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);

int n ,k;
string a = "abcdefghijklmnopqrstuvwxyz";
int main()
{
    string s;
    cin >> n >> k;
    cin >> s;
    int len = 0, can = 0 , ctr[27] = {};
    for(int i = 0; i < n; ++i)
    {
        if(s[i] >= 'A' && s[i] <= char('A' + k - 1))
        {
         //   cout << i << " ";
            int j = i + 1;
            char last = s[i];
            ctr[s[i] - 'A']++;
            if(s[i] == char('A' + k - 1))can = 1;
            while(s[j] > last && s[j] <= char('A' + k - 1) && j < n)
               last = s[j],ctr[s[j] - 'A']++,j++, (s[j] == char('A' + k - 1) ? can = 1 : 0);
            i = j - 1;
           // cout << i << "\n";
        }
    }
    len = 1000005;
    for(int i = 0; i < 26; ++i)
    if(ctr[i])
        len = min(len,ctr[i]);
    len*=k;
    can ? cout << len : cout << 0;

return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (int)1e9
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);

int n ,k;
int main()
{
    string s;
    cin >> n >> k;
    cin >> s;
    int len = 0, can = 0 , ctr[27] = {};
    for(int i = 0; i < n; ++i)
    {
        if(s[i] >= 'A' && s[i] <= char('A' + k - 1))
        {
         //   cout << i << " ";
            int j = i + 1;
            char last = s[i];
            ctr[s[i] - 'A'] = 1;
            while(s[j] > last && s[j] <= char('A' + k - 1) && j < n)
               last = s[j],ctr[s[j] - 'A']++,j++;
            i = j - 1;

           // cout << i << "\n";
        }
    }
    len = 1000005;
    for(int i = 0; i < k; ++i)
        len = min(len,ctr[i]);
    len*=k;
     cout << len;

return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (int)1e9
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);

int n ,k;
string a = "abcdefghijklmnopqrstuvwxyz";
int main()
{
    string s;
    cin >> n >> k;
    cin >> s;
    int len = 1, can = 0,ctr[27] = {};
    for(int i = 0   ; i < n; ++i)
    {

        if(s[i] == 'A')
        {
            char last = s[i];

            for(int j = i + 1; j < n ; ++j)
            {

                if(s[j] == char(k + 'A' - 1)) can = 1;
                if(s[j] - last == 1   || s[j] - last == 0)
                    last = s[j],ctr[s[j] - 'A']++;

            }
            break;
        }
    }
    for(int i = 0; i < 26; ++i)
        len = max(len , ctr[i]);
    len *= k;
    if(can)cout << len;
    else cout << 0;

return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (int)1e9
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);

int n ,k;
string a = "abcdefghijklmnopqrstuvwxyz";
int main()
{
    string s;
    cin >> n >> k;
    cin >> s;
    int len = 0, can = 0 , ctr[27] = {};
    for(int i = 0; i < n; ++i)
    {
        if(s[i] >= 'A' && s[i] <= char('A' + k - 1))
        {
            int j = i + 1;
            char last = s[i];
            ctr[s[j] - 'A']++;
            if(s[i] == char('A' + k - 1))can = 1;
            while(s[j] > last && s[j] <= char('A' + k - 1))
                last = s[j],j++,len++ ,ctr[s[j] - 'A']++, (s[j] == char('A' + k - 1) ? can = 1 : 0);
            i = j - 1;
        }
    }
    len = 1000005;
    for(int i = 0; i < 26; ++i)
    if(ctr[i])
        len = min(len,ctr[i]);
    len*=k;
    can ? cout << len : cout << 0;

return 0;
}


#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdio>
using namespace std;

#define all(v) (int)(v.begin(),v.end())
#define lp(i,n) for(int i = 0; i < n; ++i)
#define F first
#define S second
#define     sc(x)	 scanf("%d",&x)
#define scl(x)	 scanf("%I64d",&x)
#define mem(a, b) memset(a, b, sizeof(a))
#define pb push_back
#define MP make_pair
#define SORT(v) sort(all(v))
#define OO (int)1e9
#define rep(i,a,b)	for(int i=a;i<b;i++)
#define repr(i,a,b)	for(int i=a;i>=b;i--)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<vi> vvi;

const int dx[] = { 0, 0, -1, 1 , -1 , 1 , 1, -1};
const int dy[] = { -1, 1, 0, 0 , -1 , -1, 1,  1};
const int INF = 1e10;
const long long M =1e9 + 7;
const int N = 1e5 + 50;
const int MAX = 1000001;
const double PI = acos(-1.0);

//freopen("robot.in", "r", stdin);

int n ,k;
string a = "abcdefghijklmnopqrstuvwxyz";
int main()
{
    string s;
    cin >> n >> k;
    cin >> s;
    int len = 0, can = 0 , ctr[27] = {};
    for(int i = 0; i < n; ++i)
    {
        if(s[i] >= 'A' && s[i] <= char('A' + k - 1))
        {
            int j = i + 1;
            //cout << j << "\n";
            char last = s[i];
            ctr[s[i] - 'A']++;
            if(s[i] == char('A' + k - 1))can = 1;
            while(s[j] > last && s[j] <= char('A' + k - 1) && j < n)
               last = s[j],j++,ctr[s[j] - 'A']++, (s[j] == char('A' + k - 1) ? can = 1 : 0);

            i = j;
        }
    }
    len = 1000005;
    for(int i = 0; i < 26; ++i)
    if(ctr[i])
        len = min(len,ctr[i]);
    len*=k;
    can ? cout << len : cout << 0;

return 0;
}


#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int main() {
    int len, t, count = 1, min = -1;
    scanf("%d", &len);
    scanf("%d", &t);
    string str;
    cin >> str;
    //string str = temp;
    std::sort(str.begin(), str.end());
    for(int i = 1; i <= len; i++){
        if(static_cast<int>(str[i-1])==static_cast<int>(str[i])){count++;}
        else if(static_cast<int>(str[i-1])!=static_cast<int>(str[i])
        &&static_cast<int>(str[i-1])+1==static_cast<int>(str[i])){
            if(min==-1) min = count;
            min = std::min(min, count); count = 1;
        }
    }
    if(count==len) min = count;
    if(static_cast<int>(str[0])+t-1!=static_cast<int>(str[len-1])||min==-1) printf("0");
    else {cout << min*t << endl;}

}


#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
    int len, t, count = 1, pmin;
    string str;
    cin >> len >> t >> str;
    int prev = std::count(str.begin(), str.end(), 'A');
    for(int i = 66; i <= 65+t-1; i++){
        pmin = std::count(str.begin(), str.end(), (char)i);
        prev = std::min(pmin, prev);
    }
    cout << prev*t << endl;
}


#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int main() {
    int len, t, count = 1, min = -1;
    scanf("%d", &len);
    scanf("%d", &t);
    string str;
    cin >> str;
    std::sort(str.begin(), str.end());
    for(int i = 1; i <= len; i++){
        if(static_cast<int>(str[i-1])==static_cast<int>(str[i])){count++;}
        else if(static_cast<int>(str[i-1])!=static_cast<int>(str[i])
        &&static_cast<int>(str[i-1])+1==static_cast<int>(str[i])){
            if(min==-1) min = count;
            min = std::min(min, count); count = 1;
        }
    }
    if(static_cast<int>(str[0])+t-1!=static_cast<int>(str[len-1])||min==-1) printf("0");
    else {cout << min*t << endl;}

}


#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int main() {
    int len, t, count = 1, min = -1;
    scanf("%d", &len);
    scanf("%d", &t);
    char temp[len];
    cin >> temp;
    string str = temp;
    std::sort(str.begin(), str.end());
    for(int i = 1; i <= len; i++){
        if(static_cast<int>(str[i-1])==static_cast<int>(str[i])){count++;}
        else if(static_cast<int>(str[i-1])!=static_cast<int>(str[i])
        &&static_cast<int>(str[i-1])+1==static_cast<int>(str[i])){
            if(min==-1) min = count;
            min = std::min(min, count); count = 1;
        }
    }
    if(static_cast<int>(str[0])+t-1!=static_cast<int>(str[len-1])||min==-1) printf("0");
    else {cout << min*t << endl;}

}


#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
    int len, t, count = 1, pmin;
    string str;
    cin >> len >> t >> str;
    int prev = std::count(str.begin(), str.end(), 'A');
    for(int i = 66; i <= 65+t-1; i++){
        pmin = std::count(str.begin(), str.end(), (char)i);
        prev = std::min(pmin, prev);
    }
    cout << prev << endl;
}


#include <bits/stdc++.h>
using namespace std;
long long n, k, mx, mx2, kol[10000], ans;
char L, a[10000];
int main()
{
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
    {
        cin >> a[i];
    }
    int x = 1;
    sort(a + 1, a + 1 + n);
    kol[1]++;
    for(int i = 1; i <= n - 1; ++i)
    {
        //cout << a[i] << " ";
        if(a[i] != a[i + 1])
        {
            x++;
            kol[x]++;
        }
        else
        {
            kol[x]++;
            if(kol[x] > mx)
            {
                mx = kol[x];
            }
        }
    }
    if(kol[x] > mx)
    {
        mx = kol[x];
    }
    //cout << a[n] << " ";
    long long j = 1;
    /*
    cout << x << " " << mx << " ";
    for(int i = 1; i <= x; ++i)
    {
        cout << kol[i] << "  ";
    }
    cout << endl;
    */
    for(int i = 1; i <= mx; ++i)
    {
        ans = 0;
        j = 1;
        while(kol[j] >= i && j <= k)
        {
            j++;
        }
        if(j <= k)
        {
            cout << mx2;
            exit(0);
        }
        ans = k * i;
        if(ans > mx2)
        {
            mx2 = ans;
        }
    }
    cout << mx2;
}


#include <bits/stdc++.h>
using namespace std;
int n, k, mn = 1e9, b[10101];
int main()
{
    char l;
    cin >> n >> k;
    for(int i = 1; i <= n; ++ i)
    {
        cin >> l;
        b[l - 'A' + 1]++;
    }
    for(int i = 1; i <= n; ++i)
    {
        if(b[l - 'A' + 1] < mn)
        {
            mn = b[l - 'A' + 1];
        }
    }
    cout << mn * k;
}


#include <bits/stdc++.h>
using namespace std;
int n, k, mn = 1e9, b[10101];
int main()
{
    char l;
    cin >> n >> k;
    for(int i = 1; i <= n; ++ i)
    {
        cin >> l;
        b[l - 'A' + 1]++;
    }
    for(int i = 1; i <= k; ++i)
    {
        if(b[i] < mn)
        {
            mn = b[i];
        }
    }
    cout << mn * k;
}


#include <bits/stdc++.h>
using namespace std;
long long n, k, mx;
int main()
{
    char L;
    cin >> n >> k;
    for(int i = 1; i <= n; ++i)
    {
        cin >> L;
        a[L - 'A' + 1]++;
        if(a[L - 'A' + 1] > mx)
        {
            mx = a[L - 'A' + 1];
        }
    }
    cout << mx * 3;
}


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

int main(){
    int n,k,ans=0;
    cin >> n >> k;
    char s[n+5];
    int freq[26];
    memset(freq,0,sizeof freq);
    scanf("%s",s);
    for(int i=0;i<n;i++){
        freq[s[i]-'A']++;
    }
    for(int i=0;i<k;i++){
        if(freq[i]==0) {
            cout << '0' << endl;
            return 0;
        }
    }
    for(int i=0;i<k-1;i++){
        ans=min(freq[i],freq[i+1]);
    }
    ans=ans*k;
    for(int i=k;i<26;i++){
        ans+=freq[i];
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
    int n,k;
    long long ans=0;
    cin >> n >> k;
    char s[n+5];
    int freq[26];
    memset(freq,0,sizeof freq);
    scanf("%s",s);
    for(int i=0;i<n;i++){
        freq[s[i]-'A']++;
    }
    for(int i=0;i<k;i++){
        if(freq[i]==0) {
            cout << '0' << endl;
            return 0;
        }
    }
    for(int i=0;i<k-1;i++){
        ans=min(freq[i],freq[i+1]);
    }
    ans=ans*k;
    for(int i=k;i<26;i++){
        ans+=freq[i];
    }
    cout << ans << endl;

    return 0;
}


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

int main(){
    int n,k,ans=0;
    cin >> n >> k;
    char s[n+5];
    int freq[k];
    memset(freq,0,sizeof freq);
    scanf("%s",s);
    for(int i=0;i<n;i++){
        freq[s[i]-'A']++;
    }
    for(int i=0;i<k;i++){
        if(freq[i]==0) {
            cout << '0' << endl;
            return 0;
        }
    }
    for(int i=0;i<k-1;i++){
        ans=min(freq[i],freq[i+1]);
    }
    cout << ans*k << endl;

    return 0;
}


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

int main(){
    int n,k,ans=20000000;
    cin >> n >> k;
    char s[n+5];
    int freq[30];
    memset(freq,0,sizeof freq);
    scanf("%s",s);
    for(int i=0;i<n;i++){
        freq[s[i]-'A']++;
    }
    for(int i=0;i<k;i++){
        if(freq[i]==0) {
            cout << '0' << endl;
            return 0;
        }
    }
    for(int i=0;i<k;i++){
        ans=min(freq[i],ans);
    }
    ans=ans*k;
    for(int i=k;i<26;i++){
        ans+=freq[i];
    }
    cout << ans << endl;

    return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,ans,a[1000];
string s;

int main() {
	cin>>n>>k>>s;
	for(int i=0;i<s.size();i++){
		a[(int)s[i]-65]++;
	}
	int mn=1000,cnt;
	for (int i=0;i<=k;i++){
		if (a[i]<0){
		mn=min(mn,a[i]);
			cnt++;
		}
	}
	if (cnt<k) cout<<0;
	 else cout<<mn*k;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,ans,a[1000];
string s;
string q="ABCDEFHIJKLMNOPQRSTUVWXYZ";
bool z[1000];

int main() {
	cin>>n>>k>>s;
	for (int i=0;i<k;i++){
		for (int j=0;j<s.size();j++){
			if (s[j]==q[i] && z[(int)(s[j])]==0){
				ans++;
				z[(int)(s[j])]=1;
			}
		}
	}
	if(ans!=k){
		cout<<0;
		return 0;
	}
	for(int i=0;i<s.size();i++){
		a[(int)(s[i])-64]++;
	}
	int mn=100;
	for (int i=1;i<=k;i++){
		mn=min(mn,a[i]);
	}
	cout<<mn*k;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,ans,a[1000];
string s;

int main() {
	cin>>n>>k>>s;
	for(int i=0;i<s.size();i++){
		a[(int)s[i]-65]++;
	}
	int mn=1000,cnt;
	for (int i=0;i<k;i++){
		mn=min(mn,a[i]);
	}
	cout<<mn*k;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,ans,a[1000];
string s;

int main() {
	cin>>n>>k>>s;
	for(int i=0;i<s.size();i++){
		a[(int)s[i]-'A']++;
	}
	int mn=(int)1e9,cnt;
	for (int i=0;i<k;i++){
		mn=min(mn,a[i]);
	}
	cout<<mn*k;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,ans,a[1000];
string s;
string q="ABCDEFHIJKLMNOPQRSTUVWXYZ";
bool z[1000];

int main() {
	cin>>n>>k>>s;
	for(int i=0;i<s.size();i++){
		a[s[i]-'A']++;
	}
	int mn=100;
	for (int i=0;i<k;i++){
		mn=min(mn,a[i]);
	}
	cout<<mn*k;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,ans,a[1000];
string s;

int main() {
	cin>>n>>k>>s;
	for(int i=0;i<s.size();i++){
		a[(int)s[i]-64]++;
	}
	int mn=1000,cnt;
	for (int i=1;i<=k;i++){
		mn=min(mn,a[i]);
	}
	 cout<<mn*k;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,ans,a[1000];
string s;

int main() {
	cin>>n>>k>>s;
	for(int i=0;i<s.size();i++){
		a[(int)s[i]-65]++;
	}
	int mn=1000,cnt;
	for (int i=0;i<=k;i++){
		if (a[i]>0){
		mn=min(mn,a[i]);
			cnt++;
		}
	}
	if (cnt<k) cout<<0;
	 else cout<<mn*k;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,ans;
string s;
string q="ABCDEFHIJKLMNOPQRSTUVWXYZ";
bool z[1000];

int main() {
	cin>>n>>k>>s;
	for (int i=0;i<k;i++){
		for (int j=0;j<s.size();j++){
			if (s[j]==q[i] && z[(int)(s[j])]==0){
				ans++;
				z[(int)(s[j])]=1;
			}
		}
	}
	if(ans!=k){
		cout<<0;
		return 0;
	}
	int a[k];
	for(int i=0;i<s.size();i++){
		a[(int)(s[i])-64]++;
	}
	int mn=100;
	for (int i=1;i<=k;i++){
		mn=min(mn,a[i]);
	}
	cout<<mn*k;
	return 0;
}


#include <bits/stdc++.h>

using namespace std;

int n,k,a[1000];
string s;

int main() {
	cin>>n>>k>>s;
	for(int i=0;i<s.size();i++){
		a[(int)(s[i])-64]++;
	}
	int mn=100;
	for (int i=1;i<=k;i++){
		mn=min(mn,a[i]);
	}
	cout<<mn*k;
	return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{

    int n,k;
    string s;
    int freq[26];
    for(auto &it:s)
    {
        freq[it]++;
    }
    int ans=freq[0]
    for(int i=0;i<k;i++)
    {
        ans=min(ans,freq[i]);
    }
    ans*=k;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{

    int n,k;
    cin>>n>>k;
    string s;
    cin>>s;
    int freq[26];
    for(auto &it:s)
    {
        freq[it-'A']++;
    }
    int ans=freq[0];
    for(int i=0;i<k;i++)
    {
        ans=min(ans,freq[i]);
    }
    ans*=k;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n,k;
string s;
int freq[26];

int main()
{

    cin>>n>>k>>s;
    for(auto &it:s)
    {
        freq[it-'A']++;
    }
    int ans=freq[0];
    for(int i=0;i<k;i++)
    {
        ans=min(ans,freq[i]);
    }
    ans*=k;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int n,k;
string s;

int main()
{

    cin>>n>>k>>s;
    int freq[26];
    for(auto &it:s)
    {
        freq[it-'A']++;
    }
    int ans=freq[0];
    for(int i=0;i<k;i++)
    {
        ans=min(ans,freq[i]);
    }
    ans*=k;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{

    int n,k;
    string s;
    int freq[26];
    for(auto &it:s)
    {
        freq[it]++;
    }
    int ans=freq[0];
    for(int i=0;i<k;i++)
    {
        ans=min(ans,freq[i]);
    }
    ans*=k;
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main()
{

    int n,k;
    string s;
    int freq[26];
    for(auto &it:s)
    {
        freq[it-'A']++;
    }
    int ans=freq[0];
    for(int i=0;i<k;i++)
    {
        ans=min(ans,freq[i]);
    }
    ans*=k;
    cout<<ans;
    return 0;
}


//Joy Radhe,Joy Gobinda
#include<bits/stdc++.h>
using namespace std;
int main()
{
     int n,k,i,j,mn;
    int freq[26]= {0};
    string s;
    cin>>n>>k;
    cin>>s;
    for(i=0; i<s.length(); i++)
    {
        j=s[i]-65;
        freq[j]++;
    }
     mn =  100000000;
    for(i=0; i<k; i++)
    {
        mn=min(mn,freq[i]);
    }
    cout<<k*mn<<"\n";
}


//Joy Radhe,Joy Gobinda
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,j,mn;
    int freq[26]= {0};
    string s;
    cin>>n>>k;
    cin>>s;
    for(i=0; i<s.length(); i++)
    {
        j=s[i]-65;
        freq[j]++;
    }
    int mn =  10000;
    for(i=0; i<k; i++)
    {
        mn=min(mn,freq[i]);
    }
    cout<<k*mn<<"\n";
}


//Joy Radhe,Joy Gobinda
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,j,mn;
    int freq[26]= {0};
    string s;
    cin>>n>>k;
    cin>>s;
    for(i=0; i<s.length(); i++)
    {
        j=s[i]-65;
        freq[j]++;
    }
     mn =  10000;
    for(i=0; i<k; i++)
    {
        mn=min(mn,freq[i]);
    }
    cout<<k*mn<<"\n";
}


//Joy Radhe,Joy Gobinda
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k,i,j,mn;
    int freq[26]= {0};
    string s;
    cin>>n>>k;
    cin>>s;
    for(i=0; i<s.length(); i++)
    {
        j=s[i]-65;
        freq[j]++;
    }

    for(i=0; i<k; i++)
    {
        mn=min(mn,freq[i]);
    }
    cout<<k*mn<<"\n";
}


#include <iostream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int *alphabet = new int[k]();
    char c;
    for(int i = 0; i < n; ++i)
    {
        cin >> c;
        alphabet[c - 'A']++;
    }

    int min = alphabet[0];
    for(int i = 1; i < k; ++i)
    {
        if(alphabet[i] < min)
        {
            min = alphabet[i];
        }
    }
    cout << min * k << endl;
}


#include <iostream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    char *alphabet = new char[k]();
    char c;
    for(int i = 0; i < n; ++i)
    {
        cin >> c;
        alphabet[c - 'A']++;
    }

    int min = alphabet[0];
    for(int i = 1; i  < k; ++i)
    {
        if(alphabet[i] < min)
        {
            min = alphabet[i];
        }
    }
    cout << min * k << endl;
}


#include <iostream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    char alphabet[k];
    for(int i = 0; i < k; ++i)
    {
        alphabet[i] = 0;
    }
    char c;
    for(int i = 0; i < n; ++i)
    {
        cin >> c;
        alphabet[c - 'A']++;
    }

    int min = alphabet[0];
    for(int i = 1; i  < k; ++i)
    {
        if(alphabet[i] < min)
        {
            min = alphabet[i];
        }
    }
    cout << min * k << endl;
}


#include <iostream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    char alphabet[26] = {0};

    char c;
    for(int i = 0; i < n; ++i)
    {
        cin >> c;
        alphabet[c - 'A']++;
    }

    int min = alphabet[0];
    for(int i = 1; i  < k; ++i)
    {
        if(alphabet[i] < min)
        {
            min = alphabet[i];
        }
    }
    cout << min * k << endl;
}


#include <iostream>

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    char alphabet[k] = {0};

    char c;
    for(int i = 0; i < n; ++i)
    {
        cin >> c;
        alphabet[c - 'A']++;
    }

    int min = alphabet[0];
    for(int i = 1; i  < k; ++i)
    {
        if(alphabet[i] < min)
        {
            min = alphabet[i];
        }
    }
    cout << min * k << endl;
}


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

int main()
{
    int n, k, i, j,sum = 0;
    string str, t, ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    cin >> n >> k;
    cin >> str;

    vector < int > a(k, 0);

    t = ch.substr(0, k);

    for(i = 0; i < k; i++){
        sum = 0;

        for(j = 0; j < n; j++){
            if(t[i] == str[j]) sum++;
        }

        a[i] = sum;
    }

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

    cout << (k * a[0]) << endl;

    return 0;
}


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

int main()
{
    int n, k, i, j, s = 0, sum = 0;
    string str, t, ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    cin >> n >> k;
    cin >> str;

    t = ch.substr(0, k);

    for(i = 0; i < n; i++){
        for(j = 0; j < k; j++){
            if(str[i] == t[j]){
                t[j] = '0';
                s++;
            }

            if(s == k){
                sum++;
                s = 0;
                t = ch.substr(0, k);
            }
        }
    }

    cout << (sum * k) << endl;

    return 0;
}


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

int main()
{
    int n, k, i, j, s = 0, sum = 0;
    string str, t, ch = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    cin >> n >> k;
    cin >> str;

    t = ch.substr(0, k);

    for(i = 0; i < n; i++){
        for(j = 0; j < k; j++){
            if(str[i] == t[j]){
                t[j] = '0';
                s++;
            }

            if(s == k){
                sum++;
                s = 0;
                t = ch.substr(0, k);
            }
        }
    }

    if(sum == 0) cout << 0 << endl;
    else cout << (sum * k) + s << endl;

    return 0;
}


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

int a[26];

int main()
{
    int n, k;
    string s;

    cin >> n >> k >> s;

    for(int i = 0; i < n; i++) a[s[i] - 'A']++;

    int ans = 1e9;

    for(int i = 0; i < k; i++) ans = min(ans, a[i]);

    cout << ans * k << endl;

    return 0;
}


#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int times[26] = {0};

int min(int a[], int s)
{
 int i;
 int m = a[0];
 for(i = 0; i < s; i++)
  if(m > a[i])
   m = a[i];
 return m;
}

int main()
{
 int a;
 int i;
 string s;
 scanf("%*d%d", &a);
 cin >> s;
 for(i = 0; i < s.length(); i++)
  times[s[i] - 65]++;
 printf("%d\n", min(times, a) * a);
}


//
//  main.cpp
//  good Ah~~
//
//  Created by RMBP on 2019/11/5.
//  Copyright © 2019 RMBP. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,i,j,b,c,k;
    b=0;
    string a;
    cin>>n>>k>>a;
    for (c=0;c<n;c++){
        for (i=0;i<k;i++){
            for (j=0;j<a.size();j++){

                if (a[j]=='A'+i){
                    b=b+1;
                    a[j]='9';
                    break;
                }
                else {
                    c=c+1;
                }
            }
            if (c==a.size()){
                cout<<b/k*k;
                return 0;
            }
            c=0;
        }
    }
    return 0;
}


#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;

int times[26] = {0};

int min(int a[], int s)
{
 short int i;
 int m = a[0];
 for(i = 0; i < s; i++)
  if(m > a[i])
   m = a[i];
 return m;
}

int main()
{
 int a;
 short int i;
 string s;
 scanf("%*d%d", &a);
 cin >> s;
 for(i = 0; i < s.length(); i++)
  times[s[i] - 65]++;
 printf("%d\n", min(times, a) * a);
}


#include<iostream>
using namespace std;
int main(){
    int n,k,i,j,a,b,m,p;
    string s;
    char c;
    cin>>n>>k;
    cin>>s;
    int d[k];
    a=0;
    m=1;
    for(j=0;j<k;j++){
        c='A'+j;
        a=0;
        for(i=0;i<n;i++){
            if(s[i]==c)
                a=a+1;
        }
        d[j]=a;
        if(j==0)
            b=a;
        if(b>a)
            b=a;
    }
    p=b*k;
    cout<<p;
    return 0;
}


#include<iostream>
using namespace std;
int main(){
    int n,k,i,j,a,b,m,p;
    string s;
    char c;
    cin>>n>>k;
    cin>>s;
    int d[k];
    a=0;
    m=1;
    for(j=0;j<k;j++){
        c='A'+j;
        a=0;
        for(i=0;i<n;i++){
            if(s[i]==c)
                a=a+1;
        }
        d[j]=a;
        if(j==0)
            b=a;
        if(b>a)
            b=a;
    }
    p=b*k;
    for(i=0;i<k-1;i++){
        if(d[i]==d[i+1])
            m=m+1;
    }
    if(m==k)
        cout<<'0';
    else
        cout<<p;
    return 0;
}


//
//  main.cpp
//  good Ah~~
//
//  Created by RMBP on 2019/11/5.
//  Copyright © 2019 RMBP. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,i,j,b,c,k;
    b=0;
    string a;
    cin>>n>>k>>a;
    for (c=0;c<n;c++){
        for (i=0;i<k;i++){
            for (j=0;j<a.size();j++){

                if (a[j]=='A'+i){
                    b=b+1;
                    a[j]='9';
                    break;
                }
                else {
                    c=c+1;
                }
            }
            if (c==a.size()){
                cout<<b/k*k;
                break;
            }
            c=0;
        }
    }
    return 0;
}


//
//  main.cpp
//  good Ah~~
//
//  Created by RMBP on 2019/11/5.
//  Copyright © 2019 RMBP. All rights reserved.
//

#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int n,i,j,b[27]={0},c,k;
    c=1000000;
    string a;
    cin>>n>>k>>a;
    for (i=0;i<k;i++){
        for (j=0;j<a.size();j++){
            if (a[j]=='A'+i){
                b[i]=b[i]+1;
            }

        }
    }
    for (i=0;i<k;i++){
        if (c>b[i]){
            c=b[i];
        }
    }

    cout<<c*k;
    return 0;
}


#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n,min;
	string str;
	cin >> n>>n;
	cin >> str;
	vector<int>v1(n);
	for (int i = 0; i<str.length(); i++)
	{
		v1[int(str[i]) - 65]++;
	}
	min = v1[0];
	for (int i = 0; i < n; i++)
		if (v1[i] < min)
			min = v1[i];
	cout << min*n;
	system("pause");
	return 0;
}


#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n,min;
	string str;
	cin >> n>>n;
	getline(cin, str);
	vector<int>v1(n);
	for (int i = 0; i<str.length(); i++)
	{
		v1[int(str[i]) - 65]++;
	}
	min = v1[0];
	for (int i = 0; i < n; i++)
		if (v1[i] < min)
			min = v1[i];
	cout << min;
	return 0;
}


#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n,min;
	string str;
	cin >> n>>n;
	cin >> str;
	vector<int>v1(n);
	for (int i = 0; i<str.length(); i++)
	{
		v1[int(str[i]) - 65]++;
	}
	min = v1[0];
	for (int i = 0; i < n; i++)
		if (v1[i] < min)
			min = v1[i];
	cout << min*n;
	return 0;
}


#include <iostream>
#include <string.h>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
	int n,min;
	string str;
	cin >> n>>n;
	cin >> str;
	vector<int>v1(n);
	for (int i = 0; i<str.length(); i++)
	{
		v1[int(str[i]) - 65]++;
	}
	min = v1[0];
	for (int i = 0; i < n; i++)
		if (v1[i] < min)
			min = v1[i];
	cout << min;
	return 0;
}


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

int main(){
	int m,n;
	string s;
	cin>>n>>m>>s;
	int p[100];
	memset(p,0,sizeof(p));
	for(int i{};i<n;i++) p[s[i]-'A']++;
	int len=1<<30;
	for(int i{};i<m;i++) len=min(len,p[i]);
	cout<<len*m<<endl;

return 0;
}


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

int main(){
	int m,n;
	string s;
	cin>>n>>m>>s;
	int p[100];
	memset(p,0,sizeof(0));
	for(int i{};i<n;i++) p[s[i]-'A']++;
	int len=100000000;
	for(int i{};i<m;i++) if(!p[i]){len=0;break;}
	else len=min(len,p[i]);
	cout<<len*m<<endl;

return 0;
}


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

int main(){
	int m,n;
	string s;
	cin>>n>>m>>s;
	int p[100];
	memset(p,0,sizeof(0));
	for(int i{};i<n;i++) p[s[i]-'A']++;
	int len=100000000;
	for(int i{};i<m;i++) len=min(len,p[i]);
	cout<<len*m<<endl;

return 0;
}


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

int main(){
	int m,n;
	string s;
	cin>>n>>m>>s;
	int p[100];
	memset(p,0,sizeof(0));
	for(int i{};i<n;i++) p[s[i]-'A']++;
	int len=1<<30;
	for(int i{};i<m;i++) len=min(len,p[i]);
	cout<<len*m<<endl;

return 0;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    string a;
    cin>>a;
    int b[k]={0};
    for(int i=0;i<a.length();i++)
    {
        int temp=(int)a[i];
        temp-=65;
        b[temp]++;
    }
    int min=99999;
    for(int i=0;i<k;i++)
    {
        if(b[i]<min)
            min=b[i];
    }
    cout<<min*k;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    string a;
    cin>>a;
    int b[k];
    for(int i=0;i<a.length();i++)
    {
        int temp=(int)a[i];
        temp-=65;
        b[temp]++;
    }
    int min=99999;
    for(int i=0;i<k;i++)
    {
        if(b[i]<min)
            min=b[i];
    }
    cout<<min*k;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    string a;
    cin>>a;
    int b[k]={0};
    for(int i=0;i<a.length();i++)
    {
        int temp=(int)a[i];
        temp-=65;
        b[temp]++;
    }
    long int min=1000000;
    for(int i=0;i<k;i++)
    {
        if(b[i]<min)
            min=b[i];
    }
    cout<<min*k;
}


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

int main()
{
    int n,k;
    cin>>n>>k;
    string a;
    cin>>a;
    int b[k];
    for(int i=0;i<a.length();i++)
    {
        int temp=(int)a[i];
        temp-=65;
        b[temp]++;
    }
    long int min=1000000;
    for(int i=0;i<k;i++)
    {
        if(b[i]<min)
            min=b[i];
    }
    cout<<min*k;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	string s;
	cin>>s;
	int ar[26]={0};
	for(int i=0;i<n;i++)
	ar[s[i]-'A']++;
	int  c=0,mini=10000000;
	for(int i=0;i<26;i++)
	{
		if(ar[i]!=0)
		c++;
		if(ar[i]<mini && ar[i]!=0)
		mini=ar[i];
	}
	if(c<k)
	cout<<"0";
	else
	cout<<mini*k;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	int ar[26]={0};
	for(i=0;i<n;i++)
	ar[s[i]-'a']++;
	sort(ar,ar+26);
	for(i=0;i<26;i++)
	{
		if(ar[i]!=0)
		{
			cout<<k*ar[i];
			return 0;
		}
	}
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	int ar[26]={0};
	for(i=0;i<n;i++)
	ar[s[i]-'A']++;
	sort(ar,ar+26);
	for(i=0;i<26;i++)
	{
		if(ar[i]!=0)
		{
			cout<<k*ar[i];
			return 0;
		}
	}
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
	int n,k,i;
	cin>>n>>k;
	string s;
	cin>>s;
	int ar[26]={0};
	for(i=0;i<n;i++){
		ar[s[i]-'A']++;
	}

	sort(ar,ar+26);
	int cnt=0,val=10000000;
	for(i=0;i<26;i++)
	{
		if(ar[i]!=0)
		{
		    cnt++;
		    if(ar[i]<val )
		    val=ar[i];
		}
	}
//	cout<<cnt<<endl;
	if(cnt<k)
	{
		cout<<"0";
		return 0;
	}
	else
	cout<<k*val;
}


#include <bits/stdc++.h>
                #define FILES freopen("crypt.in", "r", stdin);  freopen("crypt.out", "w", stdout)
                #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
                #define FIXED cout << fixed << setprecision(20)
                #define pb push_back
                #define pf push_front
                #define popb pop_back
                #define popf pop_front
                #define eps 1e-9
                #define mod 1000000007

                using namespace std;

                typedef long long ll;
                typedef pair<ll, ll> pll;
                typedef long double ld;
                typedef vector <vector<ll> > graf;
                typedef pair< ld, ld> pld;

                using namespace std;

                int main(){
                FAST;
                ll n, m, x=200000000, k;
                cin>>n>>k;
                vector<char> a(n), b(30);
                string s, t;
cin >> s;
                for(ll j=0; j<n; j++) {a[j]=s[j];

                b[int(a[j])-65]+=1;
                }
for(ll j=0; j<k; j++) {if (b[j]<x){x=b[j];}
                }
cout << x*k;
                }


#include <bits/stdc++.h>
                #define FILES freopen("crypt.in", "r", stdin);  freopen("crypt.out", "w", stdout)
                #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
                #define FIXED cout << fixed << setprecision(20)
                #define pb push_back
                #define pf push_front
                #define popb pop_back
                #define popf pop_front
                #define eps 1e-9
                #define mod 1000000007

                using namespace std;

                typedef long long ll;
                typedef pair<ll, ll> pll;
                typedef long double ld;
                typedef vector <vector<ll> > graf;
                typedef pair< ld, ld> pld;

                using namespace std;

                int main(){
                FAST;
                ll n, m, x=200000000, k;
                cin>>n>>k;
                vector<char> b(30);
                string s, t;
cin >> s;
 for(ll j=0; j<30; j++) {
                b[j]=0;
                }
                for(ll j=0; j<n; j++) {

                b[s[j]-'A']+=1;
                }
for(ll j=0; j<k; j++) {if (b[j]<x){x=b[j];}
                }
cout << x*k;
                }


#include <bits/stdc++.h>
                #define FILES freopen("crypt.in", "r", stdin);  freopen("crypt.out", "w", stdout)
                #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
                #define FIXED cout << fixed << setprecision(20)
                #define pb push_back
                #define pf push_front
                #define popb pop_back
                #define popf pop_front
                #define eps 1e-9
                #define mod 1000000007

                using namespace std;

                typedef long long ll;
                typedef pair<ll, ll> pll;
                typedef long double ld;
                typedef vector <vector<ll> > graf;
                typedef pair< ld, ld> pld;

                using namespace std;

                int main(){
                FAST;
                ll n, m, x=200000000, k;
                cin>>n>>k;
                vector<char> a(n), b(30);
                string s, t;
cin >> s;
 for(ll j=0; j<30; j++) {
                b[j]=0;
                }
                for(ll j=0; j<n; j++) {a[j]=s[j];

                b[int(a[j])-65]+=1;
                }
for(ll j=0; j<k; j++) {if (b[j]<x){x=b[j];}
                }
cout << x*k;
                }


#include <bits/stdc++.h>
                #define FILES freopen("crypt.in", "r", stdin);  freopen("crypt.out", "w", stdout)
                #define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
                #define FIXED cout << fixed << setprecision(20)
                #define pb push_back
                #define pf push_front
                #define popb pop_back
                #define popf pop_front
                #define eps 1e-9
                #define mod 1000000007

                using namespace std;

                typedef long long ll;
                typedef pair<ll, ll> pll;
                typedef long double ld;
                typedef vector <vector<ll> > graf;
                typedef pair< ld, ld> pld;

                using namespace std;

                int main(){
                FAST;
                ll n, m, x=200000000, k;
                cin>>n>>k;
                vector<ll> b(30);
                string s, t;
cin >> s;
 for(ll j=0; j<30; j++) {
                b[j]=0;
                }
                for(ll j=0; j<n; j++) {

                b[s[j]-'A']+=1;
                }
for(ll j=0; j<k; j++) {if (b[j]<x){x=b[j];}
                }
cout << x*k;
                }


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n,k;
	cin>>n>>k;
	int arr[k]={0};
	string str;
	cin>>str;
	for(int i=0;i<n;i++){
		arr[str[i]-'A']++;
	}
	int minn = 0;
	minn = *min_element(arr,arr+n);
	cout<<minn*k<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n,k;
	cin>>n>>k;
	int arr[k]={0};
	string str;
	cin>>str;
	for(int i=0;i<n;i++){
		arr[str[i]-'A']++;
	}
	auto minn = *min_element(arr,arr+n);
	cout<<minn*k<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n,k;
	cin>>n>>k;
	int arr[k]{};
	string str;
	cin>>str;
	for(int i=0;i<n;i++){
		arr[str[i]-'A']++;
	}
	int minn = *min_element(arr,arr+n);
	cout<<minn*k<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
	int n,k;
	cin>>n>>k;
	int arr[k]{};
	string str;
	cin>>str;
	for(int i=0;i<n;i++){
		arr[str[i]-'A']++;
	}
	auto minn = *min_element(arr,arr+k);
	cout<<minn*k<<endl;
}


#include<bits/stdc++.h>
#define ll long long
using namespace std;
int n,k;
const int inf=1e9;
char a[100005];
int sum[30];
int main()
{
    int mi=inf;
    scanf("%d%d",&n,&k);
    scanf("%s",a);
    for(int i=0;i<n;i++)
    {
        sum[a[i]-'A']++;
    }
    for(int i=0;i<k;i++)
    {
        mi=min(sum[i],mi);
    }
    printf("%d\n",mi*k);
    return 0;
}


#include <cstdio>

int main() {
    int n, k;
    char s[500005];
    int count[30] = {}, ans = 0;
    scanf("%d%d%s", &n, &k, s);
    for (int i = 0; s[i]; ++i) {
        ++count[s[i] - 'A'];
        int t = count[0];
        int same = 1;
        for (int i = 1; i < k; ++i) if (count[i] != t) {
            same = 0;
            break;
        }
        if (same) ans = t;
    }
    printf("%d\n", t);
    return 0;
}


#include   <iostream>
#include    <cstring>
#include     <cstdio>
#include      <queue>
#include        <map>
#include      <cmath>
#include     <vector>
#include  <algorithm>
#include        <set>
#include      <stack>

#define mem(x,y) memset(x,y,sizeof(x))
#define INF   1e9
#define EPS   1e-6
#define MOD   1000000007
#define PI    3.141592654

typedef long long ll;

using namespace std;

int main()
{
    //freopen("c.in", "r", stdin);
    //freopen("c.out", "w", stdout);
    int n,k;
    scanf("%d %d",&n,&k);
    char save[100010];
    int rem[27];
    scanf("%s",save);
    for(int i=0;i<n;i++)
	{
		rem[save[i]-'A'+1]++;
	}
    sort(rem+1,rem+1+k);
    printf("%d\n",rem[1]*k);
    //fclose(stdin);
    //fclose(stdout);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
char s[1000005];
int num[30]={0};
int main()
{
    int n,q;
    scanf("%d %d",&n,&q);
    scanf("%s",s);
    int ans=1000005;
    for(int i=0;i<n;i++)
        num[s[i]-'A']++;
    for(int i=0;i<q;i++)
        ans=min(ans,num[i]);
    printf("%d\n",ans*q);
}


#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<deque>
#include<set>
#include<vector>
#include<map>
#include<functional>

#define fst first
#define sc second
#define pb push_back
#define mem(a,b) memset(a,b,sizeof(a))
#define lson l,mid,root<<1
#define rson mid+1,r,root<<1|1
#define lc root<<1
#define rc root<<1|1
#define lowbit(x) ((x)&(-x))

using namespace std;

typedef double db;
typedef long double ldb;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PLL;

const db eps = 1e-6;
const int mod = 1e9+7;
const int maxn = 2e6+100;
const int maxm = 2e6+100;
const int inf = 0x3f3f3f3f;
const db pi = acos(-1.0);

char a[maxn];
int num[maxn];
int main() {
    int n,k;
    scanf("%d%d", &n,&k);
    //scanf("%s%s",s1+1,s2+1);
    scanf("%s",a+1);
    int ans =  maxn;
    for(int i = 1; i <= n; i++){
        num[a[i]-'A']++;
    }
    for(int i = 0; i < k; i++){
        ans = min(ans,num[i]);
    }printf("%lld",1ll*ans*k);
    return 0;
}


#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<stack>
#include<vector>
#include<map>
#include<set>
#include<string>

#define scan(n) scanf("%d",&n)

using namespace std;

char a[100005];
int num[27];

int main()
{
    int n,i,k;
    cin>>n>>k;
    cin>>a;
    memset(num,0,sizeof(num));
    for(i=0;i<n;i++)
    {
        num[a[i]-'A']++;
    }
    int maxnum=9999999;
    for(i=0;i<k;i++)
        if(num[i]<maxnum)
            maxnum=num[i];
    cout<<maxnum*k<<endl;
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

map<char,int>m;

int main()
{
    ios::sync_with_stdio(false);
    int n,k,ans=INT_MAX;
    string s;
    cin >> n >> k >> s;
    for(int i=0; i<n; i++) m[s[i]]++;
    for(char c='A'; c<'A'+k; c++) ans=min(m[c],ans);
    cout<<ans*k<<endl;
    return 0;
}


#include <cstdio>

int main() {
    int n, k;
    char s[500005];
    int count[30] = {};
    scanf("%d%d%s", &n, &k, s);
    for (int i = 0; s[i]; ++i) {
        ++count[s[i] - 'A'];
    }
    int ans = count[0];
    for (int i = 1; i < k; ++i) if (count[i] < ans) ans = count[i];
    printf("%d\n", ans * k);
    return 0;
}


#include <iostream>

using namespace std;

int main()
{
   int n,k,i,p=0,m=0;
   string s,c,d;
   int x='A';
   cin>>n>>k>>s;
   for(int i=x;i<'A'+k;i++)
   {
       c[m]=i;
       d[m]=i;
       m++;
   }
   int a=0;
 for(i=0;i<n;i++)
 {
     for(int j=a;j<k;j++)
     {
         if(s[i]==c[j])
         {
           s[i]=1;
           c[i]=0;
             p++;
         }
         if(p==k)
         {
             for(int w=0;w<n;w++)
                c[w]=d[w];
         }
     }
 }
 if(p<k)
    cout<<0;
 else
   cout<<p;
}


#include <iostream>
#include<algorithm>
using namespace std;

int main()
{
   int n,k,i,p=0,m=0,z=0,q[100002],v=0;
   char s[100004],c[100004];
   int x='A';
   cin>>n>>k>>s;
   for(int i=x;i<'A'+k;i++)
   {
       c[m]=i;
       m++;
   }

for(i=0;i<m;i++)
{
    for(int j=0;j<n;j++)
    {
        if(s[j]==c[i])
        p++;
    }
    q[v]=p;
    v++;
    p=0;
}
sort(q,q+v);
cout<<q[0]*k;
}


#include<iostream>
#include<string>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n, k;
	cin >> n >> k;
	string s;
	map<char, int> m;
	cin >> s;
	vector<int> a(k, 0);
	for (char c : s) {
		a[c - 'A']++;
	}
	sort(a.begin(), a.end());
	cout << a[0] * k;
	return 0;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int counts[26];

int main() {
	ios::sync_with_stdio(false);

	int n; cin >> n;
	int k; cin >> k;

	for (int i = 0; i < n; i++) {
		char c; cin >> c;
		counts[c - 'A']++;
	}

	int mn = INT_MAX;

	for (int i = 0; i < k; i++)
		mn = min(mn, counts[i]);

	cout << mn * k;
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main() {
	ios::sync_with_stdio(false);

	unordered_map<char, int> counts;

	int n; cin >> n;
	int k; cin >> k;

	for (int i = 0; i < n; i++) {
		char c; cin >> c;
		counts[c]++;
	}

	if (counts.size() < k) {
		cout << 0;
	}
	else {
		int mn = INT_MAX;

		for (pair<char, int> p : counts) {
			mn = min(mn, p.second);
		}

		cout << mn * k;
	}
}


#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <bitset>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main() {
	ios::sync_with_stdio(false);

	unordered_map<char, int> counts;

	int n; cin >> n;
	int k; cin >> k;

	for (int i = 0; i < n; i++) {
		char c; cin >> c;
		counts[c]++;
	}

	if (counts.size() < k) {
		cout << 0;
	}
	else {
		int mn = INT_MAX;
		for (pair<char, int> p : counts) {
			mn = min(mn, p.second);
		}

		int answer = 0;
		for (pair<char, int> p : counts) {
			if (p.second >= mn) {
				answer += mn;
			}
		}

		cout << answer;
	}

}


#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#include <iostream>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <queue>

using namespace std;

#define fastInp ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef long double ld;

const ll SIZE = 1e6 * 2, MOD = 1e9 + 7;
vector<ll> vec;
ll q, cnt[26];

ll gcd(ll a, ll b) {
	if (b == 0)
		return a;
	else
		return gcd(b, a % b);
}

int main() {
	fastInp;

	ll n, k;
	cin >> n >> k;
	string line;
	cin >> line;

	for (int i = 0; i < line.size(); i++) {
		cnt[line[i] - 'A']++;
	}

	ll ans = INT64_MAX;
	for (int i = 0; i < k; i++) {
		ans = min(ans, cnt[i]);
	}

	cout << ans * k;

	return 0;
}