#include <bits/stdc++.h>
using namespace std;
long long min(long long a, long long b) { return (a < b) ? a : b; }
long long max(long long a, long long b) { return (a > b) ? a : b; }
long long n, m;
vector<vector<long long> > a, a2;
vector<long long> j, k;
vector<long long> vis, vis2;
bool cycleExists = 0;
void dfs(long long cur) {
  vis[cur] = 1;
  for (long long i = 0; i < a[cur].size(); i++) {
    long long v = a[cur][i];
    if (vis[v] == 0) dfs(v);
    if (cycleExists)
      return;
    else if (vis[v] == 1) {
      cycleExists = 1;
      return;
    }
  }
  vis[cur] = 2;
}
vector<char> ans;
vector<long long> dnum, dmin;
long long dc = 0;
vector<long long> top;
void dfs2(int cur, vector<vector<long long> >& A) {
  vis2[cur] = 1;
  for (int i = 0; i < A[cur].size(); i++) {
    int v = A[cur][i];
    if (!vis2[v]) dfs2(v, A);
  }
  top.push_back(cur);
}
void d3(int cur) {
  vis2[cur] = 1;
  for (int i = 0; i < a2[cur].size(); i++) {
    int v = a2[cur][i];
    if (!vis2[v]) d3(v);
    dmin[cur] = min(dmin[cur], dmin[v]);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> m;
  j.assign(m, 0), k.assign(m, 0);
  for (long long i = 0; i < m; i++) cin >> j[i] >> k[i];
  vector<long long> c;
  a.assign(n + 1, c);
  a2.assign(n + 1, c);
  vis.assign(n + 1, 0);
  vis2.assign(n + 1, 0);
  for (long long i = 0; i < m; i++) {
    a[j[i]].push_back(k[i]);
    a2[k[i]].push_back(j[i]);
  }
  for (long long i = 1; i <= n; i++) {
    if (!vis[i]) dfs(i);
  }
  if (cycleExists) {
    cout << -1 << endl;
    return 0;
  }
  ans.assign(n + 1, 'E');
  for (int i = 1; i <= n; i++)
    if (!vis2[i]) dfs2(i, a);
  vector<long long> v1(n + 1, 0), v2(n + 1, 0);
  for (int i = 0; i < top.size(); i++) {
    v1[top[i]] = top[i];
    for (int j = 0; j < a[top[i]].size(); j++) {
      v1[top[i]] = min(v1[top[i]], v1[a[top[i]][j]]);
    }
  }
  reverse(top.begin(), top.end());
  for (int i = 0; i < top.size(); i++) {
    v2[top[i]] = top[i];
    for (int j = 0; j < a2[top[i]].size(); j++) {
      v2[top[i]] = min(v2[top[i]], v2[a2[top[i]][j]]);
    }
  }
  int cnt = 0;
  for (int i = 1; i <= n; i++) {
    if (min(v1[i], v2[i]) == i) {
      cnt++;
      ans[i] = 'A';
    }
  }
  cout << cnt << endl;
  for (int i = 1; i <= n; i++) cout << ans[i];
  cout << endl;
  return 0;
}
