#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[10];
bool ok = 1;
int main() {
  scanf("%d%d", &n, &m);
  memset(a, 0, sizeof(a));
  int tmp1, tmp2;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &tmp1, &tmp2);
    if (tmp1 == 1 && tmp2 == 0) {
      ok = 0;
    }
    if (a[tmp1] == 0 || a[tmp1] == tmp2) {
      a[tmp1] = tmp2;
      continue;
    }
    ok = 0;
  }
  if (ok) {
    for (int i = 1; i <= n; i++) {
      if (i == 1 && a[i] == 0) {
        cout << "1";
      } else {
        cout << a[i];
      }
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
