#include <bits/stdc++.h>
using namespace std;
int a[5];
int main() {
  int n, m;
  while (~scanf("%d %d", &n, &m)) {
    memset(a, 0, sizeof a);
    int flag = 0;
    while (m--) {
      int x, y;
      scanf("%d %d", &x, &y);
      if (a[x] == 0) {
        a[x] = y;
      } else if (y == a[x]) {
        continue;
      } else {
        flag = 1;
        continue;
      }
    }
    if (a[1] == 0) flag = 1;
    if (flag)
      printf("-1\n");
    else {
      for (int i = 1; i <= n; i++) printf("%d", a[i]);
      printf("\n");
    }
  }
  return 0;
}
