#include <bits/stdc++.h>
using namespace std;
int a[4];
map<int, int> mp;
int main() {
  string str;
  int n, m, s, c, maxn = -1, minn = 4;
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &s, &c);
    mp[s]++;
    maxn = max(maxn, s);
    minn = min(minn, s);
    if (mp[s] > 1 && c != a[s]) {
      printf("-1\n");
      return 0;
    }
    a[s] = c;
  }
  if (mp[1] == 0 && n != 1) {
    printf("-1\n");
    return 0;
  }
  if (mp[1] > 0 && a[1] == 0 && n != 1) {
    printf("-1\n");
    return 0;
  }
  for (int i = 1; i <= n; i++) printf("%d", a[i]);
  printf("\n");
  return 0;
}
