#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e6 + 7;
int n, m, a[3];
int main() {
  int s[10], c[10], flag = 0;
  memset(a, 0, sizeof(a));
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &s[i], &c[i]);
    if (s[i] == 1 && c[i] == 0) {
      flag = 1;
      printf("-1");
    }
    for (int j = 0; j < i; j++) {
      if (s[i] == s[j]) {
        if (c[i] != c[j]) {
          flag = 1;
          printf("-1");
        }
      } else {
        a[s[i] - 1] = c[i];
      }
    }
  }
  if (flag == 0) {
    for (int i = 0; i < 3; i++) {
      printf("%d", a[i]);
    }
  }
  return 0;
}
