#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100000 + 3;
int a[10], n, m, p, d;
int main() {
  while (1) {
    for (int i = 0; i < 10; i++) a[i] = -1;
    cin >> n >> m;
    int flag = 0;
    for (int i = 0; i < m; i++) {
      cin >> p >> d;
      if (a[p] != -1 && a[p] != d) {
        flag = 1;
      }
      a[p] = d;
    }
    if (a[1] == 0 && n > 1) {
      flag = 1;
    }
    if (flag) {
      printf("-1\n");
      return 0;
    }
    if (a[1] == -1) {
      if (n > 1)
        a[1] = 1;
      else
        a[1] = 0;
    }
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      if (a[i] == -1) a[i] = 0;
      ans = ans * 10 + a[i];
    }
    cout << ans << endl;
  }
  return 0;
}
