#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using int64 = long long int;
template <typename T>
void chmax(T &a, T b) {
  a = max(a, b);
}
template <typename T>
void chmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chadd(T &a, T b) {
  a = a + b;
}
int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const int INF = 1LL << 29;
const ll LONGINF = 1LL << 60;
const ll MOD = 1000000007LL;
int main() {
  int N, M;
  scanf("%d%d", &N, &M);
  vector<int> indeg(N), outdeg(N);
  vector<vector<int> > G(N), H(N);
  for (int i = 0; i < M; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    G[u].emplace_back(v);
    H[v].emplace_back(u);
    indeg[v]++;
    outdeg[u]++;
  }
  string ans(N, 'E');
  int cnt = 0;
  vector<bool> appears(N);
  queue<int> que;
  vector<int> start;
  for (int i = 0; i < N; i++) {
    if (indeg[i] == 0) {
      start.emplace_back(i);
      appears[i] = true;
      que.emplace(i);
    }
  }
  while (que.size()) {
    int u = que.front();
    que.pop();
    for (auto v : G[u]) {
      if (--indeg[v] == 0) {
        appears[v] = true;
        que.emplace(v);
      }
    }
  }
  int cnt_appear = count(appears.begin(), appears.end(), true);
  if (cnt_appear != N) {
    puts("-1");
    return 0;
  }
  vector<int> forward(N), backward(N);
  auto bfs = [&](vector<vector<int> > &graph, vector<int> &f, int s) {
    queue<int> que;
    que.emplace(s);
    while (que.size()) {
      int u = que.front();
      que.pop();
      for (auto v : graph[u]) {
        if (!f[v]) {
          f[v] = true;
          que.emplace(v);
        }
      }
    }
  };
  for (int i = 0; i < N; i++) {
    if (!forward[i] and !backward[i]) ans[i] = 'A', cnt++;
    if (!forward[i]) bfs(G, forward, i);
    if (!backward[i]) bfs(H, backward, i);
  }
  printf("%d\n%s\n", cnt, ans.c_str());
  return 0;
}
