#if 1
#ifdef LOCAL
#define _GLIBCXX_DEBUG 1
#define dbg(...) cerr << "LINE(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define dbg(...) 0
#endif

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

#if 0
    #include <bits/extc++.h>
    using namespace __gnu_pbds;

    template<class T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
        tree_order_statistics_node_update>;
#endif

#if 0
    /* #include <sys/time.h>
    int main() {
	    timeval tp;
	    gettimeofday(&tp, 0);
	    C = (int)tp.tv_usec; // (less than modulo)
    */

    typedef uint64_t ull;
    static int C;

    template<int M, class B>
    struct A {
        int x; B b; A(int x=0) : x(x), b(x) {}
        A(int x, B b) : x(x), b(b) {}
        A operator+(A o){int y = x+o.x; return{y - (y>=M)*M, b+o.b};}
        A operator-(A o){int y = x-o.x; return{y + (y< 0)*M, b-o.b};}
        A operator*(A o) { return {(int)(1LL*x*o.x % M), b*o.b}; }
        explicit operator ull() { return x ^ (ull) b << 21; }
    };
    typedef A<1000000007, A<1000000009, unsigned>> H;

    struct HashInterval {
        vector<H> ha, pw;
        HashInterval(string& str) : ha(sz(str)+1), pw(ha) {
            pw[0] = 1;
            rep(i,0,sz(str))
                ha[i+1] = ha[i] * C + str[i],
                pw[i+1] = pw[i] * C;
        }
        H hashInterval(int a, int b) { // hash [a, b)
            return ha[b] - ha[a] * pw[b - a];
        }
    };

    H hashString(string& s){H h{}; for(char c:s) h=h*C+c;return h;}
#endif

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)

typedef string str;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename T, typename U> T &ctmax(T &x, const U &y){ return x = max<T>(x, y); }
template<typename T, typename U> T &ctmin(T &x, const U &y){ return x = min<T>(x, y); }

mt19937 rng((unsigned)chrono::steady_clock::now().time_since_epoch().count());

#define ts to_string
str ts(char c) { return str(1,c); }
str ts(bool b) { return b ? "true" : "false"; }
str ts(const char* s) { return (str)s; }
str ts(str s) { return s; }
template<class A> str ts(complex<A> c) { stringstream ss; ss << c; return ss.str(); }
str ts(vector<bool> v) { str res = "{"; F0R(i,sz(v)) res += char('0'+v[i]);	res += "}"; return res; }
template<size_t SZ> str ts(bitset<SZ> b) { str res = ""; F0R(i,SZ) res += char('0'+b[i]); return res; }
template<class A, class B> str ts(pair<A,B> p);
template<class T> str ts(T v) { bool fst = 1; str res = "{"; for (const auto& x: v) {if (!fst) res += ", ";	fst = 0; res += ts(x);}	res += "}"; return res;}
template<class A, class B> str ts(pair<A,B> p) {return "("+ts(p.first)+", "+ts(p.second)+")"; }

template<class A> void pr(A x) { cout << ts(x); }
template<class H, class... T> void pr(const H& h, const T&... t) { pr(h); pr(t...); }
void ps() { pr("\n"); }
template<class H, class... T> void ps(const H& h, const T&... t) { pr(h); if (sizeof...(t)) pr(" "); ps(t...); }

void DBG() { cerr << "]" << endl; }
template<class H, class... T> void DBG(H h, T... t) {cerr << ts(h); if (sizeof...(t)) cerr << ", ";	DBG(t...); }

int myrand(int l, int r) { return uniform_int_distribution(l, r)(rng); }

template<typename T, typename U> struct seg_tree_lazy {
    int S, H;

    T zero;
    std::vector<T> value;

    U noop;
    std::vector<bool> dirty;
    std::vector<U> prop;

    seg_tree_lazy<T, U>(int _S, T _zero = T(), U _noop = U());
    void set_leaves(std::vector<T> &leaves);
    void apply(int i, U &update);
    void rebuild(int i);
    void propagate(int i);
    void upd(int i, int j, U update);
    T query(int i, int j);
};

template<typename T, typename U>
seg_tree_lazy<T, U>::seg_tree_lazy(int _S, T _zero, U _noop) {
        zero = _zero, noop = _noop;
        for (S = 1, H = 1; S < _S; ) S *= 2, H++;

        value.resize(2*S, zero);
        dirty.resize(2*S, false);
        prop.resize(2*S, noop);
    }

template<typename T, typename U>
void seg_tree_lazy<T, U>::set_leaves(vector<T> &leaves) {
    copy(leaves.begin(), leaves.end(), value.begin() + S);

    for (int i = S - 1; i > 0; i--)
        value[i] = value[2 * i] + value[2 * i + 1];
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::apply(int i, U &update) {
    value[i] = update(value[i]);
    if(i < S) {
        prop[i] = prop[i] + update;
        dirty[i] = true;
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::rebuild(int i) {
    for (int l = i/2; l; l /= 2) {
        T combined = value[2*l] + value[2*l+1];
        value[l] = prop[l](combined);
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::propagate(int i) {
    for (int h = H; h > 0; h--) {
        int l = i >> h;

        if (dirty[l]) {
            apply(2*l, prop[l]);
            apply(2*l+1, prop[l]);

            prop[l] = noop;
            dirty[l] = false;
        }
    }
}

template<typename T, typename U>
void seg_tree_lazy<T, U>::upd(int i, int j, U update) {
    i += S, j += S;
    propagate(i), propagate(j);

    for (int l = i, r = j; l <= r; l /= 2, r /= 2) {
        if((l&1) == 1) apply(l++, update);
        if((r&1) == 0) apply(r--, update);
    }

    rebuild(i), rebuild(j);
}

template<typename T, typename U>
T seg_tree_lazy<T, U>::query(int i, int j){
    i += S, j += S;
    propagate(i), propagate(j);

    T res_left = zero, res_right = zero;
    for(; i <= j; i /= 2, j /= 2){
        if((i&1) == 1) res_left = res_left + value[i++];
        if((j&1) == 0) res_right = value[j--] + res_right;
    }
    return res_left + res_right;
}

/*struct node {
    ll val = 0;

    node operator+(node ot) {
        ot.val = max(val, ot.val);
        return ot;
    }
};

struct update {
    ll val = 0;

    node operator()(node ot) {
        ot.val += val;
        return ot;
    }

    update operator+(update ot) {
        ot.val += val;
        return ot;
    }
};*/

#endif

vector<int> g[1100000];
vi seen;

int dfs(int v) {
    if (seen[v]) return 0;
    seen[v] = 1;

    int r = 1;
    for (int x: g[v]) {
        r += dfs(x);
    }

    return r;
}

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

    int n,m,k;
    cin >> n >> m >> k;
    seen = vi(n);

    for (int i = 0; i < m; i++) {
        int u,v;
        cin >> u >> v;
        u--; v--;
        g[u].push_back(v);
        g[v].push_back(u);
    }

    int comps = 0;
    int conns = 0;
    int isolated = 0;
    for (int i = 0; i < n; i++) if (!seen[i]) {
        if (g[i].empty()) {
            isolated++;
        }
        else {
            conns += min(k, dfs(i));
            comps++;
        }
    }

    conns -= max(0, 2*comps - 2);
    dbg(isolated,conns);
    cout << max(0, (isolated - conns + 1) / 2 - (comps==0) ) << endl;
    return 0;
}


#include <bits/stdc++.h>
#define pb push_back
using namespace std;
vector<int> v[1000001];
int n,m,k,a,b,cnt,sum;
bool vis[1000001];
int dfs(int a,int fa)
{
	vis[a]=true;
	int ans=1;
	for (int i=0;i<v[a].size();i++)
	{
		if (vis[v[a][i]]) continue;
		ans+=dfs(v[a][i],a);
	}
	return ans;
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m>>k;
	while (m--) cin>>a>>b,v[a].pb(b),v[b].pb(a);
	for (int i=1;i<=n;i++) if (!vis[i]) sum+=min(dfs(i,i),k),cnt++;
	if (k==1) cout<<max(cnt-2,0);
	else if (cnt==1) cout<<0;
	else cout<<max(0,cnt-1-sum/2);
	return 0;
}


#include <bits/stdc++.h>
#define MAXV 1000010
using namespace std;
int parent[MAXV],rank[MAXV],a[1000010],sz,iso,N,M,K,x,y;
struct UnionFind{
    UnionFind(int n){
        int i;
        for (int i=0;i<n;i++) {parent[i] = i; rank[i] = 1;}
    }
    int root(int x){
        if(parent[x] != x) parent[x] = root(parent[x]);
        return parent[x];
    }
    void connect(int x, int y){
        int rx=root(x),ry=root(y);
        if(rx == ry) return;
        if(rank[rx] > rank[ry]) {parent[ry] = rx; rank[rx] += rank[ry];}
        if(rank[rx] <= rank[ry]) {parent[rx] = ry; rank[ry] += rank[rx];}
    }
};
int func(int N, int K){
    if(K==1)
	{
        if(sz+iso<=2) return 0;
        return sz+iso-2;
    }
    int sum=0;
    for (int i=0;i<sz;i++) sum+=min(K,a[i]);
    sum+=iso;
    int ans=0;
    while(1)
	{
        if(sum>=2*(sz+iso-1)) return ans;
        ans++;
        iso-=2,sum-=2;
        a[sz]=2; sz++; sum+=min(2,K);
    }
}
int main()
{
    cin>>N>>M>>K;
    UnionFind uf(N);
    for (int i=0;i<M;i++)
	{
        cin>>x>>y;
		x--; y--;
        uf.connect(x,y);
    }
    for (int i=0;i<N;i++)
		if(uf.root(i)==i)
		{
        	if(rank[i]==1) iso++;
			else a[sz]=rank[i],sz++;
    	}
    int ans=func(N,K);
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k;
const ll maxn = 1e6 + 6;
vector<ll> G[maxn];
bool vis[maxn];
ll d[maxn];
ll dfs(ll u)
{
	ll res = 1;
	vis[u] = 1;
	for(int j : G[u])
	{
		if(!vis[j])
		{
			res += dfs(j);
		}
	}
	return res;
}
multiset<ll> s;
int main(int argc, char const *argv[])
{
	cin>>n>>m>>k;
	for(int i = 0;i < m; ++i)
	{
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	ll dCount = 0;
	for(ll i = 0;i < n; ++i)
	{
		if(!vis[i])
		{
			d[dCount++] = dfs(i);
		}
	}
	sort(d,d + dCount);
	reverse(d,d + dCount);
	ll total = 0;
	for(int i = 0;i < dCount; ++i)
	{
		if(d[i] > k)
		{
			d[i] = k;
		}
		total += d[i];
		s.insert(d[i]);
	}
	for(int i = 0;; ++i)
	{
		if(total >= 2 * (s.size() - 1))
		{
			cout<<i<<endl;
			return 0;
		}
		ll a = *s.begin();
		s.erase(s.begin());
		ll b = *s.begin();
		s.erase(s.begin());
		total = total - a - b + min(a + b,k);
		s.insert(min(a + b,k));
	}
	return 0;
}


#include <bits/stdc++.h>
#define REP(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define MAXV 1000010
using namespace std;
int parent[MAXV],rank[MAXV],a[1000010],sz,iso;
struct UnionFind{
    UnionFind(int n){
        int i;
        REP(i,n) {parent[i] = i; rank[i] = 1;}
    }
    int root(int x){
        if(parent[x] != x) parent[x] = root(parent[x]);
        return parent[x];
    }
    void connect(int x, int y){
        int rx=root(x),ry=root(y);
        if(rx == ry) return;
        if(rank[rx] > rank[ry]) {parent[ry] = rx; rank[rx] += rank[ry];}
        if(rank[rx] <= rank[ry]) {parent[rx] = ry; rank[ry] += rank[rx];}
    }
};
int func(int N, int K){
    if(K == 1){
        if(sz + iso <= 2) return 0;
        return sz + iso - 2;
    }
    int sum = 0;
    int i;
    REP(i,sz) sum += min(K,a[i]);
    sum += iso;
    int ans = 0;
    while(1){
        if(sum >= 2 * (sz + iso - 1)) return ans;
        ans++;
        iso -= 2; sum -= 2;
        a[sz] = 2; sz++; sum += min(2,K);
    }
}
int main()
{
    int N,M,K,i,x,y;
    cin>>N>>M>>K;
    UnionFind uf(N);
    REP(i,M){
        cin>>x>>y;
		x--; y--;
        uf.connect(x,y);
	}
    REP(i,N)
		if(uf.root(i)==i)
		{
        	if(rank[i]==1) iso++;
        	else a[sz]=rank[i],sz++;
    	}
    int ans=func(N,K);
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
int cnt,j,n,m,k,i,cnt1,sum,fr,re;
int ss[2000010],ff[2000010],pred[2000010];
int last[1000010],x[1000010],was[1000010];
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>k;
    for(i=1;i<=m;i++){
        cin>>ss[i]>>ff[i];
        ss[i+m]=ff[i];
        ff[i+m]=ss[i];
    }
    for(i=1;i<=m+m;i++){
        pred[i]=last[ss[i]];
        last[ss[i]]=i;
    }
    cnt1=0;sum=2;
    cnt=0;
    for(j=1;j<=n;j++)
        if(!was[j]){
            fr=1;re=1;
            x[1]=j;
            was[j]=true;
            while(fr<=re){
                i=last[x[fr]];
                while(i>0){
                    if(!was[ff[i]]){
                        re++;
                        x[re]=ff[i];
                        was[x[re]]=true;
                    }
                    i=pred[i];
                }
                fr++;
            }
            cnt++;
            if(re>k) re=k;
            if(re==1) cnt1++;
            else sum+=re-2;
        }
    if(cnt==1)cout<<0;
    else if(k==1) cout<<cnt-2;
    else if(cnt1<=sum) cout<<0;
    else cout<<(cnt1-sum+1)/2;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e6+7;
int n,m,k,a,b,cc,cc1,ans,fa[N],sz[N];
int findf(int a)
{
	return fa[a]==a ? a : fa[a]=findf(fa[a]);
}
int main()
{
	cin>>n>>m>>k;
	for (int i=1;i<=n;i++) fa[i]=i,sz[i]=1;
	while (m--)
	{
		cin>>a>>b;
		a=findf(a);
		b=findf(b);
		if (a!=b) fa[a]=b,sz[b]+=sz[a];
	}
	for (int i=1;i<=n;i++)
		if (findf(i)==i)
		{
			cc++;
			if (sz[i]==1) cc1++;
		}
	if (cc=1)
	{
		cout<<"0";
		return 0;
	}
	while (cc1*2>n)
	{
		cc1-=2;
		cc--;
		ans++;
	}
	cout<<ans+max(cc-1-k,0);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
#define F first
#define S second
#define random(x) (rand()%x)
const int maxn=1000005,INF=0x3f3f3f3f,mod=1000000007;
vi eg[maxn];
int vis[maxn];
int dfs(int v)
{
	vis[v]=1;
	int ans=1;
	for(int i=0;i<eg[v].size();i++)
		if(!vis[eg[v][i]])
			ans+=dfs(eg[v][i]);
	return ans;
}
int main(){
	int n,m,k,u,v,s=0,c=0;
	cin>>n>>m>>k;
	for(int i=0;i<m;i++)
	{
		cin>>u>>v;
		eg[u].push_back(v);
		eg[v].push_back(u);
	}
	for(int i=1;i<=n;i++)
		if(!vis[i])
		{
			c++;
			s+=min(k,dfs(i));
		}
	if(k==1) cout<<max(c-2,0);
	else cout<<max(0,(2*c-s-1)/2);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,m,k,x,y;
const ll maxn=1e6+6;
vector<ll> G[maxn];
bool vis[maxn];
ll d[maxn];
ll dfs(ll u)
{
	ll res=1;
	vis[u]=1;
	for(int j : G[u])
		if(!vis[j])
			res+=dfs(j);
	return res;
}
multiset<ll> s;
int main(int argc, char const *argv[])
{
	cin>>n>>m>>k;
	for(int i=0;i<m;++i)
	{
		cin>>x>>y;
		x--,y--;
		G[x].push_back(y);
		G[y].push_back(x);
	}
	ll dCount=0;
	for(ll i=0;i<n;++i)
		if(!vis[i])
			d[dCount++]=dfs(i);
	sort(d,d+dCount);
	reverse(d,d+dCount);
	ll total=0;
	for(int i=0;i<dCount;++i)
	{
		if(d[i]>k) d[i]=k;
		total+=d[i];
		s.insert(d[i]);
	}
	for(int i=0;;++i)
	{
		if(total>=2*(s.size()-1))
		{
			cout<<i<<endl;
			return 0;
		}
		ll a=*s.begin();
		s.erase(s.begin());
		ll b=*s.begin();
		s.erase(s.begin());
		total=total-a-b+min(a+b,k);
		s.insert(min(a+b,k));
	}
	return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
typedef long long ll;
#define MAX 1000005
using namespace std;
int n,m,k;
#define INF 2147483647
#define MOD 1000000007
#define EPS 1e-6
#define G 9.8
bool debug = false;

int a,b,ss;
vector<int> mp[MAX];
bool v[MAX];
void dfs(int i) {
    if (v[i]) return;
    v[i]=1; ss++;
    for (vector<int>::iterator it=mp[i].begin(); it!=mp[i].end(); it++) {
        dfs(*it);
    }
}
int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for(int i=0;i<m;i++) {
        scanf("%d%d", &a,&b);
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    int sum = 0;
    vector<int> coms;
    for(int i=1;i<=n;i++)if (!v[i]) {
        ss = 0; dfs(i);
        sum += min(ss,k);
        coms.push_back(ss);
    }
    sort(coms.begin(),coms.end());
    int ans = 0, yu = 0;
    vector<int> ::reverse_iterator it=coms.rbegin();
    int sumk = *it;
    for (it++; it!=coms.rend();it++) {
        if (sumk > 0) {
            sumk += (*it) -2;
            if (*it < k) yu += k- *it;
        } else {
            ans++;
            int plus = min(yu, *it);
            sumk+=plus; yu-=plus;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
typedef long long ll;
#define MAX 1000005
using namespace std;
int n,m,k;
#define INF 2147483647
#define MOD 1000000007
#define EPS 1e-6
#define G 9.8
bool debug = false;

int a,b,ss;
vector<int> mp[MAX];
bool v[MAX];
void dfs(int i) {
    if (v[i]) return;
    v[i]=1; ss++;
    for (vector<int>::iterator it=mp[i].begin(); it!=mp[i].end(); it++) {
        dfs(*it);
    }
}
int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for(int i=0;i<m;i++) {
        scanf("%d%d", &a,&b);
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    //int sum = 0;
    vector<int> coms;
    for(int i=1;i<=n;i++)if (!v[i]) {
        ss = 0; dfs(i);
        coms.push_back(min(ss,k));
    }
    sort(coms.begin(),coms.end());
    int ans = 0, yu = 0;
    vector<int> ::reverse_iterator it=coms.rbegin();
    int sumk = *it;
    for (it++; it!=coms.rend();it++) {
        if (sumk > 0) {
            sumk += (*it) -2;
            if (*it < k) yu += k- *it;
        } else {
            ans++;
            int plus = min(yu, *it);
            sumk+=plus; yu-=plus;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
typedef long long ll;
#define MAX 1000005
using namespace std;
int n,m,k;
#define INF 2147483647
#define MOD 1000000007
#define EPS 1e-6
#define G 9.8
bool debug = false;

int a,b,ss;
vector<int> mp[MAX];
bool v[MAX];
void dfs(int i) {
    if (v[i]) return;
    v[i]=1; ss++;
    for (vector<int>::iterator it=mp[i].begin(); it!=mp[i].end(); it++) {
        dfs(*it);
    }
}
int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for(int i=0;i<m;i++) {
        scanf("%d%d", &a,&b);
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    //int sum = 0;
    vector<int> coms;
    for(int i=1;i<=n;i++)if (!v[i]) {
        ss = 0; dfs(i);
        coms.push_back(min(ss,k));
    }
    sort(coms.begin(),coms.end());
    int ans = 0;
    ll yu = 0;
    vector<int> ::reverse_iterator it=coms.rbegin();
    ll sumk = *it;
    for (it++; it!=coms.rend();it++) {
        if (sumk > 0) {
            sumk += (*it) -2;
            if (*it < k) yu += k- *it;
        } else {
            ans++;
            ll plus = min(yu, (ll)*it);
            sumk+=plus; yu-=plus;
        }
    }
    printf("%d\n",ans);
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <cmath>
#include <set>
#include <map>
#include <cstdio>
#include <stdlib.h>
#include <stack>
#include <numeric>
#include <bitset>
typedef long long ll;
#define MAX 1000005
using namespace std;
int n,m,k;
#define INF 2147483647
#define MOD 1000000007
#define EPS 1e-6
#define G 9.8
bool debug = false;

int a,b,ss;
vector<int> mp[MAX];
bool v[MAX];
void dfs(int i) {
    if (v[i]) return;
    v[i]=1; ss++;
    for (vector<int>::iterator it=mp[i].begin(); it!=mp[i].end(); it++) {
        dfs(*it);
    }
}
int main()
{
    scanf("%d%d%d", &n, &m, &k);
    for(int i=0;i<m;i++) {
        scanf("%d%d", &a,&b);
        mp[a].push_back(b);
        mp[b].push_back(a);
    }
    int sum = 0, com = 0;
    for(int i=1;i<=n;i++)if (!v[i]) {
        com++; ss = 0; dfs(i);
        sum += min(ss,k);
    }
    int ans = com - sum/2;
    printf("%d\n",ans > 1 ? ans-1 : 0);
    return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int n,m,k,cnt=0,num=0;
bool vis[1000004];
vector <int> g[1000004];
int dfs(int x){
	int res=1;
	vis[x]=1;
	for (int i=0;i<g[x].size();i++){
		if (vis[g[x][i]]) continue;
		res+=dfs(g[x][i]);
	}
	return res;
}
int main(){
	cin>>n>>m>>k;
	for (int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int pp;
	for (int i=1;i<=n;i++){
		if (vis[i]) continue;
		num+=min(dfs(i),k);
		cnt++;
	}
	int tt=2*(cnt-1)-num;
	if (tt<=0) return !printf("0");
	int oo=num/2;
	cout<<cnt-1-oo;
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int n,m,k,cnt=0,num=0;
bool vis[1000004];
vector <int> g[1000004];
int dfs(int x){
	int res=1;
	vis[x]=1;
	for (int i=0;i<g[x].size();i++){
		if (vis[g[x][i]]) continue;
		res+=dfs(g[x][i]);
	}
	return res;
}
int main(){
	cin>>n>>m>>k;
	for (int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int pp;
	for (int i=1;i<=n;i++){
		if (vis[i]) continue;
		num+=min(dfs(i),k);
		cnt++;
	}
	if (k==1){
		cout<<cnt-2;
		return 0;
	}
	int tt=2*(cnt-1)-num;
	if (tt<=0) return !printf("0");
	int oo=num/2;
	cout<<cnt-1-oo;
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
const int MAXN=1<<20;
struct Disjoinset{
	int p[MAXN],c[MAXN];
	void init(int n){
		for (int i=0;i<n;++i){
			p[i]=i;
			c[i]=1;
		}
	}
	int root(int i){
		return i==p[i]?i:(p[i]=root(p[i]));
	}
	void setp(int i,int j){
		i=root(i);
		j=root(j);
		if (i==j){
			return;
		}
		if (c[i]>c[j]){
			swap(i,j);
		}
		p[i]=j;
		c[j]+=c[i];
	}
}ds;
int main(){
	int n,m,q,s,a,b;
	vector <int> c;
	scanf("%d%d%d",&n,&q,&m);
	ds.init(n);
	for (int i=0;i<q;++i){
		scanf("%d%d",&a,&b);
		ds.setp(a-1,b-1);
	}
	for (int i=0;i<n;++i){
		if (ds.root(i)==i){
			c.push_back(ds.c[i]);
		}
	}
	if (c.size()==1){
		puts("0");
	}else if (m==1){
		printf("%d\n",max(0,(int)c.size()-2));
	}else{
		q=count(c.begin(),c.end(),1);
		c.erase(remove(c.begin(),c.end(),1),c.end());
		if (c.empty()){
			q=q-1;
			s=1;
		}else{
			s=0;
			for (int i=0;i<(int)c.size();++i){
				s+=min(c[i],m);
			}
			s-=2*((int)c.size()-1);
		}
		printf("%d\n",max(0,(q-s+1)/2));
	}
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int n,m,k,cnt=0,num=0;
bool vis[1000004];
vector <int> g[1000004];
int dfs(int x){
	int res=1;
	vis[x]=1;
	for (int i=0;i<g[x].size();i++){
		if (vis[g[x][i]]) continue;
		res+=dfs(g[x][i]);
	}
	return res;
}
int main(){
	cin>>n>>m>>k;
	for (int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int pp;
	for (int i=1;i<=n;i++){
		if (vis[i]) continue;
		num+=min(dfs(i),k);
		cnt++;
	}
	if (k==1){
		cout<<cnt-1;
		return 0;
	}
	int tt=2*(cnt-1)-num;
	if (tt<=0) return !printf("0");
	int oo=num/2;
	cout<<cnt-1-oo;
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int n,m,k,cnt=0,num=0;
bool vis[1000004];
vector <int> g[1000004];
int dfs(int x){
	int res=1;
	vis[x]=1;
	for (int i=0;i<g[x].size();i++){
		if (vis[g[x][i]]) continue;
		res+=dfs(g[x][i]);
	}
	return res;
}
int main(){
	cin>>n>>m>>k;
	for (int i=0;i<m;i++){
		int x,y;
		scanf ("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int pp;
	for (int i=1;i<=n;i++){
		if (vis[i]) continue;
		num+=min(dfs(i),k);
		cnt++;
	}
	if (k==1){
		cout<<max(0,cnt-2);
		return 0;
	}
	int tt=2*(cnt-1)-num;
	if (tt<=0) return !printf("0");
	int oo=num/2;
	cout<<cnt-1-oo;
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
#define forn(i,n) for(int i=0;i<(n);++i)
#define forv(i,v) for(int i=0;i<(int)v.size();++i)
#define pb push_back
vector <int> gr[1100000];
int comp[1100000];
int n;
int dfs(int v,int c){
	if (comp[v]) return 0;
	int r=1;
	comp[v]=c;
	forv(i,gr[v])
		r+=dfs(gr[v][i],c);
	return r;
}
int main(){
	cin>>n;
	int m,k;
	cin>>m>>k;
	forn (i,m){
		int a,b;
		scanf ("%d%d",&a,&b);
		--a,--b;
		gr[a].pb(b);
		gr[b].pb(a);
	}
	int c=0;
	int ones=0;
	int s=0;
	bool was=false;
	forn(i,n)
		if (!comp[i]){
			int t=dfs(i,++c);
			t=min(t,k);
			if (t==1) ++ones;
			else{
				s+=t-2;
				was=true;
			}
		}
	if (k==1){
		cout<<max(0,c-2);
		return 0;
	}
	cout<<max(0,(ones-s-1)/2);
	return 0;
}


#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int n,m,k,cnt=0,num=0;
bool vis[1000004];
vector <int> g[1000004];
int dfs(int x){
	int res=1;
	vis[x]=1;
	for (int i=0;i<g[x].size();i++){
		if (vis[g[x][i]]) continue;
		res+=dfs(g[x][i]);
	}
	return res;
}
int main(){
	cin>>n>>m>>k;
	for (int i=0;i<m;i++){
		int x,y;
		scanf ("%d%d",&x,&y);
		g[x].push_back(y);
		g[y].push_back(x);
	}
	int pp;
	for (int i=1;i<=n;i++){
		if (vis[i]) continue;
		num+=min(dfs(i),k);
		cnt++;
	}
	if (k==1){
		cout<<cnt-2;
		return 0;
	}
	int tt=2*(cnt-1)-num;
	if (tt<=0) return !printf("0");
	int oo=num/2;
	cout<<cnt-1-oo;
	return 0;
}


#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

int p[N];

int find(int x) {
  if (x == p[x]) {
    return x;
  }
  return p[x] = find(p[x]);
}

void unite(int x, int y) {
  x = find(x);
  y = find(y);
  p[x] = y;
}

void solve(int) {
  cin >> n >> m;
  vector<int> active(m), in(n);
  vector<vector<int>> g(n);
  iota(p, p + n, 0);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    ++in[y];
    unite(x, y);
  }
  string ans(n, 'E');
  vector<vector<int>> mn(n), mx(n);
  for (int i = 0; i < n; ++i) {
    int c = find(i);
    if (!in[i]) {
      mx[c].push_back(i);
    }
    if (g[i].empty()) {
      mn[c].push_back(i);
    }
  }
  for (int i = 0; i < n; ++i) {
    if (mn.size() > mx.size()) {
      for (int id : mn[i]) {
        ans[id] = 'A';
      }
    } else {
      for (int id : mx[i]) {
        ans[id] = 'A';
      }
    }
  }
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    if (!in[i]) {
      q.push(i);
    }
  }
  int visited = 0;
  while (!q.empty()) {
    ++visited;
    int v = q.front();
    q.pop();
    for (int u : g[v]) {
      --in[u];
      if (!in[u]) {
        q.push(u);
      }
    }
  }
  if (visited != n) {
    cout << "-1\n";
    return;
  }
  cout << count(begin(ans), end(ans), 'A') << '\n' << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

vector<int> g[N], rg[N];
int used1[N], used2[N];

void dfs1(int v) {
  used1[v] = 1;
  for (int u : g[v]) {
    if (!used1[u]) {
      dfs1(u);
    }
  }
}

void dfs2(int v) {
  used2[v] = 1;
  for (int u : rg[v]) {
    if (!used2[u]) {
      dfs2(u);
    }
  }
}

void solve(int) {
  cin >> n >> m;
  vector<int> active(m), in(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    rg[y].push_back(x);
    ++in[y];
  }
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    if (!in[i]) {
      q.push(i);
    }
  }
  int visited = 0;
  while (!q.empty()) {
    ++visited;
    int v = q.front();
    q.pop();
    for (int u : g[v]) {
      --in[u];
      if (!in[u]) {
        q.push(u);
      }
    }
  }
  if (visited != n) {
    cout << "-1\n";
    return;
  }
  string ans(n, 'E');
  for (int i = 0; i < n; ++i) {
    if (!used1[i] && !used2[i]) {
      ans[i] = 'A';
    }
    dfs1(i);
    dfs2(i);
  }
  cout << count(begin(ans), end(ans), 'A') << '\n' << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
#include <cctype>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
//template<typename key, typename val>
//using ordered_tree =
//  tree<key, val, std::less<>, rb_tree_tag, tree_order_statistics_node_update>;
using namespace std;
typedef long long int64;
typedef unsigned long long uint64;
typedef complex<double> comp;
const double pi = 3.14159265358979323846;
const int inf = (int)1e+9 + 2;
const int64 inf64 = (int64)1e+18 + 2;
const double dinf = 1e+20;
const int mod = 1'000'000'007;//*/998244353;
const int base = 2187;
const double eps = 1e-9;
const int N = 300'000;
const int LOGN = 19;

int n, m, k;

vector<int> g[N], rg[N];
int used1[N], used2[N];

void dfs1(int v) {
  used1[v] = 1;
  for (int u : g[v]) {
    dfs1(u);
  }
}

void dfs2(int v) {
  used2[v] = 1;
  for (int u : rg[v]) {
    dfs2(u);
  }
}

void solve(int) {
  cin >> n >> m;
  vector<int> active(m), in(n);
  for (int i = 0; i < m; ++i) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    g[x].push_back(y);
    rg[y].push_back(x);
    ++in[y];
  }
  queue<int> q;
  for (int i = 0; i < n; ++i) {
    if (!in[i]) {
      q.push(i);
    }
  }
  int visited = 0;
  while (!q.empty()) {
    ++visited;
    int v = q.front();
    q.pop();
    for (int u : g[v]) {
      --in[u];
      if (!in[u]) {
        q.push(u);
      }
    }
  }
  if (visited != n) {
    cout << "-1\n";
    return;
  }
  string ans(n, 'E');
  for (int i = 0; i < n; ++i) {
    if (!used1[i] && !used2[i]) {
      ans[i] = 'A';
    }
    dfs1(i);
    dfs2(i);
  }
  cout << count(begin(ans), end(ans), 'A') << '\n' << ans << '\n';
}

void precalc() {
}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  precalc();
  int test = 1;
  //cin >> test;
  //auto start = chrono::high_resolution_clock::now();
  for (int i = 1; i <= test; ++i) {
    solve(i);
  }
  //cerr << chrono::duration_cast<chrono::milliseconds>(chrono::high_resolution_clock::now() - start).count() << '\n';
  return 0;
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

bool dfs(vi* v, vii &vv, int x, int* vis, int* vis2, int xx, int m, int n)
{
    vis[x]=xx;
    rep(i,v[x].size())
    {
        int y=v[x][i];
        if(vis[y]==xx)
            return false;
        else if(vis[y])
            continue;
        bool aa=dfs(v,vv,v[y][i],vis,vis2,xx,m,n);
        if(aa==false)
            return false;
    }
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1], vis2[m+1];
    memset(vis,0,sizeof(vis));
    memset(vis2,0,sizeof(vis2));
    int xx=1;
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(vv[i].se);
    }
    repu(i,1,n)
    {
        if(vis2[i]==0)
        {
            bool aa = dfs(v,vv,1,vis,vis2,xx,m,n);
            if(aa==false)
            {
                return false;
            }
            xx++;
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

bool dfs(vi* v, vii &vv, int x, int* vis, int* vis2, int xx, int m, int n)
{
    vis[x]=xx;
    rep(i,v[x].size())
    {
        int y=v[x][i];
        if(vis[y]==xx)
            return false;
        else if(vis[y])
            continue;
        bool aa = true;
        aa=dfs(v,vv,y,vis,vis2,xx,m,n);
        if(aa==false)
            return false;
    }
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1], vis2[m+1];
    memset(vis,0,sizeof(vis));
    memset(vis2,0,sizeof(vis2));
    int xx=1;
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(vv[i].se);
    }
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            bool aa=true;
            aa = dfs(v,vv,i,vis,vis2,xx,m,n);
            if(aa==false)
            {
                return false;
            }
            xx++;
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

void dfs(vi* v, int x, int* vis)
{
    vis[x]=1;
    rep(i,v[x].size())
    {
        int y=v[x][i];
        if(vis[y]==1)
        {
            cout<<-1<<endl;
            exit(0);
        }
        else if(vis[y]==2)
            continue;
        dfs(v,y,vis);
    }
    vis[x]=2;
    return;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            dfs(v1,i,vis);
        }
    }
    memset(vis,0,sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

bool dfs(vi* v, vii vv, int x, int* vis, int* vis2, int xx, int m, int n)
{
    vis[vv[x].fi]=xx;
    // cout<<vv[x].fi<<" "<<vv[x].se<<endl;
    if(vis[vv[x].se]==xx)
    {
        return false;
    }
    int y=vv[x].se;
    vis2[x]=1;
    rep(i,v[y].size())
    {
        if(vis2[v[y][i]]==1)
            continue;
        bool aa=dfs(v,vv,v[y][i],vis,vis2,xx,m,n);
        if(aa==false)
            return false;
    }
    vis[vv[x].fi]=0;
    return true;
}

bool check(vii vv, int m, int n)
{
    int vis[n+1], vis2[m+1];
    memset(vis,0,sizeof(vis));
    memset(vis2,0,sizeof(vis2));
    int xx=1;
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(i);
    }
    repu(i,1,m)
    {
        if(vis2[i]==0)
        {
            bool aa = dfs(v,vv,1,vis,vis2,xx,m,n);
            if(aa==false)
            {
                return false;
            }
            xx++;
        }
    }
    return true;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    repu(i,1,n)
    {
        if(vv[i].se==0)
            x++;
    }
    cout<<x<<endl;
    repu(i,1,n)
    {
        if(vv[i].se==0)
            cout<<"A";
        else
            cout<<"E";
    }
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

bool dfs(vi* v, int x, int* vis)
{
    vis[x]=1;
    rep(i,v[x].size())
    {
        int y=v[x][i];
        if(vis[y]==1)
            return false;
        else if(vis[y]==2)
            continue;
        bool aa = true;
        aa=dfs(v,y,vis);
        if(aa==false)
            return false;
    }
    vis[x]=2;
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1];
    memset(vis,0,sizeof(vis));
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(vv[i].se);
    }
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            bool aa=true;
            aa = dfs(v,1,vis);
            if(aa==false)
            {
                return false;
            }
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

bool dfs(vi* v, vii &vv, int x, int* vis, int* vis2, int xx, int m, int n)
{
    vis[vv[x].fi]=xx;
    // cout<<vv[x].fi<<" "<<vv[x].se<<endl;
    if(vis[vv[x].se]==xx)
    {
        return false;
    }
    int y=vv[x].se;
    vis2[x]=1;
    rep(i,v[y].size())
    {
        if(vis2[v[y][i]]==1)
            continue;
        bool aa=dfs(v,vv,v[y][i],vis,vis2,xx,m,n);
        if(aa==false)
            return false;
    }
    vis[vv[x].fi]=0;
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1], vis2[m+1];
    memset(vis,0,sizeof(vis));
    memset(vis2,0,sizeof(vis2));
    int xx=1;
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(i);
    }
    repu(i,1,m)
    {
        if(vis2[i]==0)
        {
            bool aa = dfs(v,vv,i,vis,vis2,xx,m,n);
            if(aa==false)
            {
                return false;
            }
            xx++;
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

bool dfs(vi* v, vii &vv, int x, int* vis, int* vis2, int xx, int m, int n)
{
    vis[vv[x].fi]=xx;
    // cout<<vv[x].fi<<" "<<vv[x].se<<endl;
    if(vis[vv[x].se]==xx)
    {
        return false;
    }
    int y=vv[x].se;
    vis2[x]=1;
    rep(i,v[y].size())
    {
        if(vis2[v[y][i]]==1)
            continue;
        bool aa=dfs(v,vv,v[y][i],vis,vis2,xx,m,n);
        if(aa==false)
            return false;
    }
    vis[vv[x].fi]=0;
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1], vis2[m+1];
    memset(vis,0,sizeof(vis));
    memset(vis2,0,sizeof(vis2));
    int xx=1;
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(i);
    }
    repu(i,1,m)
    {
        if(vis2[i]==0)
        {
            bool aa = dfs(v,vv,1,vis,vis2,xx,m,n);
            if(aa==false)
            {
                return false;
            }
            xx++;
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

bool dfs(vi* v, vii &vv, int x, int* vis, int* vis2, int xx, int m, int n)
{
    vis[x]=xx;
    rep(i,v[x].size())
    {
        int y=v[x][i];
        if(vis[y]==xx)
            return false;
        else if(vis[y])
            continue;
        bool aa = true;
        aa=dfs(v,vv,y,vis,vis2,xx,m,n);
        if(aa==false)
            return false;
    }
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1], vis2[m+1];
    memset(vis,0,sizeof(vis));
    memset(vis2,0,sizeof(vis2));
    int xx=1;
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(vv[i].se);
    }
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            bool aa=true;
            aa = dfs(v,vv,1,vis,vis2,xx,m,n);
            if(aa==false)
            {
                return false;
            }
            xx++;
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

ll t=0;

bool dfs(vi* v, int x, int* vis, vi &start, vi &end)
{
    vis[x]=1;
    start[x]=t;
    t++;
    rep(i,v[x].size())
    {
        int y=v[x][i];
        if(vis[y] && end[y]==-1)
            return false;
        else if(vis[y])
            continue;
        bool aa = true;
        aa=dfs(v, y, vis, start, end);
        if(aa==false)
            return false;
    }
    end[x]=t;
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1];
    memset(vis,0,sizeof(vis));
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(vv[i].se);
    }
    vi start(n+1,-1), end(n+1,-1);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            bool aa=true;
            aa = dfs(v,1,vis,start,end);
            if(aa==false)
            {
                return false;
            }
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

bool dfs(vi* v, vii &vv, int x, int* vis, int* vis2, int xx, int m, int n)
{
    vis[x]=xx;
    rep(i,v[x].size())
    {
        int y=v[x][i];
        if(vis[y]==xx)
            return false;
        else if(vis[y])
            continue;
        bool aa = true;
        aa=dfs(v,vv,y,vis,vis2,xx,m,n);
        if(aa==false)
            return false;
    }
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1], vis2[m+1];
    memset(vis,0,sizeof(vis));
    memset(vis2,0,sizeof(vis2));
    int xx=1;
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(vv[i].se);
    }
    repu(i,1,n)
    {
        if(vis2[i]==0)
        {
            bool aa=true;
            aa = dfs(v,vv,1,vis,vis2,xx,m,n);
            if(aa==false)
            {
                return false;
            }
            xx++;
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>
/* Uncomment only if you are not using GNU compiler->
#include <map> #include <algorithm> #include <vector> #include <string.h> #include <math.h> #include <stdio.h> #include <stdlib.h> #include <chrono> #include <thread> #include <iomanip>
*/
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define all(v)  v.begin(), v.end()

//typedef
typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;

const long long MOD = 998244353;
const long long inf = 1e18;

using namespace std;

vll fact(400001), inv_fact(400001);

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}

int power(int x, int n)
{
    int res=1;
    while(n>0){
        if(n&1) res=res*x;
        x=x*x;
        n>>=1;
    }
    return res;
}

// void pre()
// {
//     fact[0]=fact[1]=1;
//     inv_fact[0]=inv_fact[1]=1;
//     repu(i,2,400000)
//     {
//         fact[i]=fact[i-1]*i;
//         fact[i]%=MOD;
//         inv_fact[i]=inv_fact[i-1]*modpow(i, MOD-2);
//         inv_fact[i]%=MOD;
//     }
// }

ll t=0;

bool dfs(vi* v, int x, int* vis, vi &start, vi &end)
{
    vis[x]=1;
    start[x]=t;
    t++;
    rep(i,v[x].size())
    {
        int y=v[x][i];
        if(vis[y] && end[y]==-1)
            return false;
        else if(vis[y])
            continue;
        bool aa = true;
        aa=dfs(v, y, vis, start, end);
        if(aa==false)
            return false;
    }
    end[x]=t;
    return true;
}

bool check(vii &vv, int m, int n)
{
    int vis[n+1];
    memset(vis,0,sizeof(vis));
    vi v[n+1];
    repu(i,1,m)
    {
        v[vv[i].fi].pb(vv[i].se);
    }
    vi start(n+1,-1), end(n+1,-1);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            bool aa=true;
            aa = dfs(v,i,vis,start,end);
            if(aa==false)
            {
                return false;
            }
        }
    }
    return true;
}

int dfs2(int* vis, vi* v1, int x, int xx, vi &up)
{
    vis[x]=1;
    int ans=x;
    rep(i,v1[x].size())
    {
        int y=v1[x][i];
        if(vis[y]==1)
        {
            ans=min(ans, up[y]);
            continue;
        }
        ans=min(ans,dfs2(vis, v1, y, xx, up));
    }
    up[x]=ans;
    return ans;
}

void solve()
{
    int n, m;
    cin>>n>>m;
    vii v, vv;
    vi v1[n+1], v2[n+1];
    int x, y;
    rep(i,n+1)
        vv.pb(mp(0,0));
    v.pb(mp(0,0));
    rep(i,m)
    {
        cin>>x>>y;
        vv[x].fi++;
        vv[y].se++;
        v1[x].pb(y);
        v2[y].pb(x);
        v.pb(mp(x,y));
    }
    x=0;
    if(check(v,m,n)==false)
    {
        cout<<-1<<endl;
        return;
    }
    int vis[n+1];
    char str[n+1];
    str[n]='\0';
    int ans=0;
    rep(i,n)
        str[i]='E';
    memset(vis, 0, sizeof(vis));
    vi up(n+1,0), down(n+1,0);
    repu(i,1,n)
    {
        if(vis[i]==0)
        {
            int aa=dfs2(vis, v1, i, i, up);
            int bb=dfs2(vis, v2, i, i, down);
            if(aa>=i && bb>=i)
            {
                ans++;
                str[i-1]='A';
            }
        }
    }
    cout<<ans<<endl;
    cout<<str;
    cout<<endl;
}

int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("ee.txt", "w", stdout);
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1, tt=1;
    // pre();
    // cin>>t;
    while(tt<=t)
    {
        // cout<<"Case #"<<tt<<": ";
        solve();
        tt++;
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

ll n,m;
const ll M = 2*1e5+7;

vll ng[M];
vll ngp[M];
bool assigned[M];
bool ok = 1;
unordered_set<ll> vis;

void dfs(ll u, vll*ng) {
    if(vis.count(u)) { ok=0; return; }
    if(assigned[u]) return;
    vis.insert(u);
    assigned[u] = 1;
    for(auto v: ng[u]) {
        dfs(v, ng);
    }
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    F(m) {
        ll a, b; cin >> a >> b;
        a--; b--;
        ng[a].pb(b);
        ngp[b].pb(a);
    }
    ll cnt = 0;
    string ret = string(n,'E');
    F(n) {
        // for each A we remove all predecesors & successors
        //  (there can't be 2 As on a path!)
        // assign As in order of vars
        if(!assigned[i]) {
            vis.clear(); dfs(i,ng);
            assigned[i]=0;
            vis.clear(); dfs(i,ngp);
            ret[i]='A';
            cnt++;
        }
    }
    if(!ok) cout << -1 << endl;
    else {
        cout << cnt << endl;
        cout << ret << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

ll n,m;
const ll M = 2*1e5+7;

vll ng[M];
vll ngg[M];
ll deg[M];

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    F(m) {
        ll a, b; cin >> a >> b;
        a--; b--;
        ng[a].pb(b);
        ngg[b].pb(a);
    }
    queue<ll> q;
    set<ll> src;
    F(n) {
        deg[i] = ngg[i].size();
        if(deg[i]==0) { q.push(i); src.insert(i); }
    }
    bool ok = 1;
    ll vis = 0;
    while(q.size()) {
        auto cur = q.front(); q.pop();
        vis++;
        for(auto u: ng[cur]) {
            deg[u]--;
            if(deg[u]==0) q.push(u);
        }
    }
    ok &= vis==n;
    if(!ok) cout << -1 << endl;
    else {
        cout << src.size() << endl;
        F(n) cout << (src.count(i)?"A":"E");
        cout << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

ll n,m;
const ll M = 2*1e5+7;

vll ng[M];
vll ngp[M];
ll deg[M];
bool ass[M];
bool assp[M];
bool ok = 1;

void dfs(ll u, bool*assigned, vll*ng) {
    if(assigned[u]) return;
    assigned[u] = 1;
    for(auto v: ng[u]) {
        dfs(v, assigned, ng);
    }
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    F(m) {
        ll a, b; cin >> a >> b;
        a--; b--;
        ng[a].pb(b);
        ngp[b].pb(a);
    }
    queue<ll> q;
    ll vis = 0;
    F(n) {
        deg[i]=ngp[i].size();
        if(!deg[i]) q.push(i);
    }
    while(q.size()) {
        ll i = q.front(); q.pop();
        vis++;
        for(auto j: ng[i]) {
            deg[j]--;
            if(!deg[j]) q.push(j);
        }
    }
    ok = vis==n;
    ll cnt = 0;
    string ret = string(n,'E');
    F(n) {
        // for each A we remove all predecesors & successors
        //  (there can't be 2 As on a path!)
        // assign As in order of vars
        if(!ass[i] && !assp[i]) {
            ret[i]='A';
            cnt++;
        }
        dfs(i,ass,ng);
        dfs(i,assp,ngp);
    }
    if(!ok) cout << -1 << endl;
    else {
        cout << cnt << endl;
        cout << ret << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

ll n,m;
const ll M = 2*1e5+7;

vll ng[M];
vll ngp[M];
bool assigned[M];
bool ok = 1;
unordered_set<ll> vis;

void dfs(ll u, vll*ng) {
    if(vis.count(u)) { ok=0; return; }
    if(assigned[u]) return;
    vis.insert(u);
    assigned[u] = 1;
    for(auto v: ng[u]) {
        dfs(v, ng);
    }
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    F(m) {
        ll a, b; cin >> a >> b;
        a--; b--;
        ng[a].pb(b);
        ngp[b].pb(a);
    }
    ll cnt = 0;
    string ret = string(n,'E');
    F(n) {
        // for each A we remove all predecesors & successors
        //  (there can't be 2 As on a path!)
        // assign As in order of vars
        if(!assigned[i]) {
            vis.clear(); dfs(i,ng);
            vis.clear(); dfs(i,ngp);
            ret[i]='A';
            cnt++;
        }
    }
    if(!ok) cout << -1 << endl;
    else {
        cout << cnt << endl;
        cout << ret << endl;
    }
    return 0;
}


#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

ll n,m;
const ll M = 2*1e5+7;

vll ng[M];
vll ngp[M];
bool ass[M];
bool assp[M];
bool ok = 1;
unordered_set<ll> vis;

void dfs(ll u, bool*assigned, vll*ng) {
    if(vis.count(u)) { ok=0; return; }
    if(assigned[u]) return;
    vis.insert(u);
    assigned[u] = 1;
    for(auto v: ng[u]) {
        dfs(v, assigned, ng);
    }
}

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    F(m) {
        ll a, b; cin >> a >> b;
        a--; b--;
        ng[a].pb(b);
        ngp[b].pb(a);
    }
    ll cnt = 0;
    string ret = string(n,'E');
    F(n) {
        // for each A we remove all predecesors & successors
        //  (there can't be 2 As on a path!)
        // assign As in order of vars
        if(!ass[i] && !assp[i]) {
            ret[i]='A';
            cnt++;
        }
        vis.clear(); dfs(i,ass,ng);
        vis.clear(); dfs(i,assp,ngp);
    }
    if(!ok) cout << -1 << endl;
    else {
        cout << cnt << endl;
        cout << ret << endl;
    }
    return 0;
}


#include <iostream>
#include <queue>
#include <numeric>
#include <vector>
using namespace std;

const int maxN = 2e5 + 226;
queue<int> que;
int N, M, a, b, min1[maxN], min2[maxN], indeg[maxN];

vector<int> adj[maxN], rev[maxN];

int main(){
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		adj[a].push_back(b);
		rev[b].push_back(a);
	}
	for(int i = 1; i <= N; i++){
		for(int x : adj[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	int cnt = 0;
	while(que.size()){
		int t = que.front();
		que.pop();
		cnt++;
		for(int u : adj[t]){
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	if(cnt < N){
		cout << -1 << endl;
		return 0;
	}
	iota(min1, min1 + N + 1, 0);
	iota(min2, min2 + N + 1, 0);
	for(int i = 1; i <= N; i++){
		for(int x : adj[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	while(que.size()){
		int t = que.front();
		que.pop();
		for(int u : adj[t]){
			min1[u] = min(min1[u], min1[t]);
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	for(int i = 1; i <= N; i++){
		for(int x : rev[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	while(que.size()){
		int t = que.front();
		que.pop();
		for(int u : adj[t]){
			min2[u] = min(min2[u], min1[t]);
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(min1[i] == i && min2[i] == i) ans++;
	}
	cout << ans << endl;
	for(int i = 1; i <= N; i++){
		cout << ((min1[i] == i && min2[i] == i) ? 'A' : 'E');
	}
}


#include <iostream>
#include <queue>
#include <numeric>
#include <vector>
using namespace std;

const int maxN = 2e5 + 226;
queue<int> que;
int N, M, a, b, min1[maxN], min2[maxN], indeg[maxN];

vector<int> adj[maxN], rev[maxN];

int main(){
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		adj[a].push_back(b);
		rev[b].push_back(a);
	}
	for(int i = 1; i <= N; i++){
		for(int x : adj[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	int cnt = 0;
	while(que.size()){
		int t = que.front();
		que.pop();
		cnt++;
		for(int u : adj[t]){
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	if(cnt < N){
		cout << -1 << endl;
		return 0;
	}
	iota(min1, min1 + N + 1, 0);
	iota(min2, min2 + N + 1, 0);
	for(int i = 1; i <= N; i++){
		for(int x : adj[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	while(que.size()){
		int t = que.front();
		que.pop();
		for(int u : adj[t]){
			min1[u] = min(min1[u], min1[t]);
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	for(int i = 1; i <= N; i++){
		for(int x : rev[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	while(que.size()){
		int t = que.front();
		que.pop();
		for(int u : rev[t]){
			min2[u] = min(min2[u], min1[t]);
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(min1[i] == i && min2[i] == i) ans++;
	}
	cout << ans << endl;
	for(int i = 1; i <= N; i++){
		cout << ((min1[i] == i && min2[i] == i) ? 'A' : 'E');
	}
}


#include <iostream>
#include <vector>
#include <queue>
using namespace std;

const int maxN = 2e5 + 10;
vector<int> adj[maxN];
bool can[maxN], visited[maxN];
int N, M, u, v, indeg[maxN];
queue<int> que;

int main(){
	cin >> N >> M;
	fill(can, can + N + 1, 1);
	for(int i = 0; i < M; i++){
		cin >> u >> v;
		can[max(u, v)] = 0;
		adj[u].push_back(v);
		indeg[v]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	int k = 0;
	while(que.size()){
		int t = que.front();
		que.pop();
		k++;
		for(int x : adj[t]){
			indeg[x] = indeg[x] - 1;
			if(!indeg[x]) que.push(x);
		}
	}
	if(k != N){
		cout << -1 << endl;
		return 0;
    }
	int ans = 0;
	for(int i = 1; i <= N; i++) ans += can[i];
	cout << ans << endl;
	for(int i = 1; i <= N; i++) cout << (can[i] ? ‘A’ : ‘E’);
}


#include <iostream>
#include <vector>
#include <queue>
using namespace std;

const int maxN = 2e5 + 10;
vector<int> adj[maxN];
bool can[maxN], visited[maxN];
int N, M, u, v, indeg[maxN];
queue<int> que;

int main(){
	cin >> N >> M;
	fill(can, can + N + 1, 1);
	for(int i = 0; i < M; i++){
		cin >> u >> v;
		can[max(u, v)] = 0;
		adj[u].push_back(v);
		indeg[v]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	int k = 0;
	while(que.size()){
		int t = que.front();
		que.pop();
		k++;
		for(int x : adj[t]){
			indeg[x] = indeg[x] - 1;
			if(!indeg[x]) que.push(x);
		}
	}
	if(k != N){
		cout << -1 << endl;
		return 0;
    }
	int ans = 0;
	for(int i = 1; i <= N; i++) ans += can[i];
	cout << ans << endl;
	for(int i = 1; i <= N; i++) cout << (can[i] ? 'A': 'E');
}


#include <iostream>
#include <queue>
#include <numeric>
#include <vector>
using namespace std;

const int maxN = 2e5 + 226;
queue<int> que;
int N, M, a, b, min1[maxN], min2[maxN], indeg[maxN];

vector<int> adj[maxN], rev[maxN];

int main(){
	cin >> N >> M;
	for(int i = 0; i < M; i++){
		cin >> a >> b;
		adj[a].push_back(b);
		rev[b].push_back(a);
	}
	for(int i = 1; i <= N; i++){
		for(int x : adj[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	int cnt = 0;
	while(que.size()){
		int t = que.front();
		que.pop();
		cnt++;
		for(int u : adj[t]){
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	if(cnt < N){
		cout << -1 << endl;
		return 0;
	}
	iota(min1, min1 + N + 1, 0);
	iota(min2, min2 + N + 1, 0);
	for(int i = 1; i <= N; i++){
		for(int x : adj[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	while(que.size()){
		int t = que.front();
		que.pop();
		for(int u : adj[t]){
			min1[u] = min(min1[u], min1[t]);
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	for(int i = 1; i <= N; i++){
		for(int x : rev[i]) indeg[x]++;
	}
	for(int i = 1; i <= N; i++) if(!indeg[i]) que.push(i);
	while(que.size()){
		int t = que.front();
		que.pop();
		for(int u : rev[t]){
			min2[u] = min(min2[u], min2[t]);
			indeg[u]--;
			if(!indeg[u]) que.push(u);
		}
	}
	int ans = 0;
	for(int i = 1; i <= N; i++){
		if(min1[i] == i && min2[i] == i) ans++;
	}
	cout << ans << endl;
	for(int i = 1; i <= N; i++){
		cout << ((min1[i] == i && min2[i] == i) ? 'A' : 'E');
	}
}


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int n, m;
  vector<int> V[maxn], VV[maxn];
  int in[maxn];
  void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      V[u].push_back(v);
      VV[v].push_back(u);
      in[v]++;
    }
    if (topo()) {
      cout << -1;
      return;
    }
    string ans;
    int anscount = 0;
    for (int i = 1; i <= n; ++i) {
      if (!vis[i] && !vis2[i]) {
        ans += "A";
        anscount++;
      } else {
        ans += "E";
      }
      dfs2(i);
      dfs1(i);
    }
    cout << anscount << "\n"
         << ans;
  }
  bool vis[maxn], vis2[maxn];
  void dfs1(int u) {
    vis[u] = 1;
    for (int j : V[u]) {
      if (!vis[j]) dfs1(j);
    }
  }
  void dfs2(int u) {
    vis2[u] = 1;
    for (int j : VV[u])
      if (!vis2[j]) dfs2(j);
  }
  bool topo() {
    vector<int> que;
    for (int i = 1; i <= n; ++i) {
      if (in[i] == 0) {
        que.push_back(i);
      }
    }
    for (int i = 0; i < que.size(); ++i) {
      for (int j : V[que[i]]) {
        in[j]--;
        if (in[j] == 0) {
          que.push_back(j);
        }
      }
    }
    if (que.size() != n) return true;
    return false;
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int n, m;
  vector<int> V[maxn], VV[maxn];
  int in[maxn];
  void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      V[u].push_back(v);
      VV[v].push_back(u);
      in[v]++;
    }
    if (topo()) {
      cout << -1;
      return;
    }
    string ans;
    int anscount = 0;
    for (int i = 1; i <= n; ++i) {
      if (!vis[i] && !vis2[i]) {
        ans += "A";
        anscount++;
        dfs1(i);
        dfs2(i);
      } else {
        ans += "E";
      }
    }
    cout << anscount << "\n"
         << ans;
  }
  bool vis[maxn], vis2[maxn];
  void dfs1(int u) {
    if (vis[u]) return;
    vis[u] = 1;
    for (int j : V[u]) {
      dfs1(j);
    }
  }
  void dfs2(int u) {
    if (vis2[u]) return;
    vis2[u] = 1;
    for (int j : VV[u]) dfs2(u);
  }
  bool topo() {
    vector<int> que;
    for (int i = 1; i <= n; ++i) {
      if (in[i] == 0) {
        que.push_back(i);
      }
    }
    for (int i = 0; i < que.size(); ++i) {
      for (int j : V[que[i]]) {
        in[j]--;
        if (in[j] == 0) {
          que.push_back(j);
        }
      }
    }
    if (que.size() != n) return true;
    return false;
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int n, m;
  vector<int> V[maxn];
  pi save[maxn];
  int in[maxn];
  void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
      cin >> save[i].first >> save[i].second;
      V[save[i].first].push_back(save[i].second);
      in[save[i].second]++;
    }
    if (topo()) {
      cout << -1;
      return;
    }
    for (int i = 0; i < m; ++i) {
      V[save[i].second].push_back(save[i].first);
    }
    string ans;
    int anscount = 0;
    for (int i = 1; i <= n; ++i) {
      if (!vis[i]) {
        ans += "A";
        anscount++;
        dfs(i);
      } else {
        ans += "E";
      }
    }
    cout << anscount << "\n"
         << ans;
  }
  bool vis[maxn];
  void dfs(int u) {
    if (vis[u]) return;
    vis[u] = 1;
    for (int v : V[u]) {
      dfs(v);
    }
  }
  bool topo() {
    vector<int> que;
    for (int i = 1; i <= n; ++i) {
      if (in[i] == 0) {
        que.push_back(i);
      }
    }
    for (int i = 0; i < que.size(); ++i) {
      for (int j : V[que[i]]) {
        in[j]--;
        if (in[j] == 0) {
          que.push_back(j);
        }
      }
    }
    if (que.size() != n) return true;
    return false;
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}


#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#else
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
 public:
  int n, m;
  vector<int> V[maxn], VV[maxn];
  int in[maxn];
  void solve() {
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
      int u, v;
      cin >> u >> v;
      V[u].push_back(v);
      VV[v].push_back(u);
      in[v]++;
    }
    if (topo()) {
      cout << -1;
      return;
    }
    string ans;
    int anscount = 0;
    for (int i = 1; i <= n; ++i) {
      if (!vis[i] && !vis2[i]) {
        ans += "A";
        anscount++;
        dfs1(i);
        dfs2(i);
      } else {
        ans += "E";
      }
    }
    cout << anscount << "\n"
         << ans;
  }
  bool vis[maxn], vis2[maxn];
  void dfs1(int u) {
    if (vis[u]) return;
    vis[u] = 1;
    for (int j : V[u]) {
      dfs1(j);
    }
  }
  void dfs2(int u) {
    if (vis2[u]) return;
    vis2[u] = 1;
    for (int j : V[u]) dfs2(u);
  }
  bool topo() {
    vector<int> que;
    for (int i = 1; i <= n; ++i) {
      if (in[i] == 0) {
        que.push_back(i);
      }
    }
    for (int i = 0; i < que.size(); ++i) {
      for (int j : V[que[i]]) {
        in[j]--;
        if (in[j] == 0) {
          que.push_back(j);
        }
      }
    }
    if (que.size() != n) return true;
    return false;
  }
} NSPACE;
int main() {
  FPEN;
  ios_base::sync_with_stdio(false);
  cout.tie(0);
  cin.tie(0);
  NSPACE.solve();
}