#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int s[6], c[6], ans[3];
  cin >> N >> M;
  for (long long i = 0; i < (long long)(M); i++) cin >> s[i] >> c[i];
  for (long long i = 0; i < (long long)(3); i++) ans[i] = 0;
  for (long long i = 0; i < (long long)(M); i++) {
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (ans[s[i] - 1] != -1 && ans[s[i] - 1] != c[i] && ans[s[i] - 1] != 0) {
      cout << "a" << endl;
      cout << -1 << endl;
      return 0;
    } else {
      ans[s[i] - 1] = c[i];
      if (s[i] == 3) {
        if (ans[1] == -1) ans[1] = 0;
        if (ans[0] == -1) ans[0] = 0;
      } else if (s[i] == 2) {
        if (ans[0] == -1) ans[0] = 0;
      }
    }
  }
  for (int i = 0; i < 3; i++) {
    if (ans[i] != -1) {
      cout << ans[i];
    }
  }
  cout << endl;
}
