#include <bits/stdc++.h>
using namespace std;
struct node {
  int s, c;
} a[10];
int main() {
  int n, m, ans[10][2], flag = 0, t = 0;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &a[i].s, &a[i].c);
  }
  memset(ans, 0, sizeof(ans));
  for (int i = 1; i <= m; i++) {
    if (ans[a[i].s][0] == 0) {
      ans[a[i].s][0] = 1;
      ans[a[i].s][1] = a[i].c;
      t++;
    } else {
      if (ans[a[i].s][1] != a[i].c) {
        flag = 1;
        break;
      }
    }
  }
  if (flag == 1 || t > n) {
    printf("-1\n");
  } else {
    if (n == 1) {
      if (ans[1][0] == 1) {
        printf("%d\n", ans[1][0]);
      } else {
        printf("0\n");
      }
    } else {
      if (ans[1][0] == 1 && ans[1][1] == 0) {
        printf("-1\n");
      } else {
        for (int i = 1; i <= n; i++) {
          printf("%d", ans[i][1]);
        }
        printf("\n");
      }
    }
  }
  return 0;
}
