#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  int s[6];
  int c[6];
  int s1[6];
  int num[5];
  memset(num, -1, sizeof(num));
  for (int i = 1; i <= m; i++) {
    cin >> s[i] >> c[i];
    s1[i] = s[i];
  }
  int f = 0;
  for (int i = 1; i <= m; i++) {
    if (s[i] == 1 && c[i] == 0) f = 1;
  }
  for (int i = 1; i <= m; i++) {
    for (int j = 1; j <= m; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) f = 1;
      }
    }
  }
  if (f == 1) {
    cout << -1 << endl;
  } else {
    for (int i = 1; i <= m; i++) {
      num[s1[i]] = c[i];
    }
    for (int i = 1; i <= 3; i++) {
      if (num[i] == -1) {
        if (i != 1) {
          num[i] = 0;
        } else {
          num[i] = 1;
        }
      }
    }
    printf("%d%d%d\n", num[1], num[2], num[3]);
  }
  return 0;
}
