#include <bits/stdc++.h>
using namespace std;
int main() {
  int q, w, a[10], qwe;
  while (cin >> q >> w) {
    if (q == 1 && !w) {
      cout << 0 << endl;
      continue;
    }
    memset(a, -1, sizeof(a));
    qwe = 0;
    for (int i = 1; i <= w; i++) {
      int s, d;
      cin >> s >> d;
      if (q != 1 && s == 1 && d == 0)
        qwe = 1;
      else if (a[s] == -1)
        a[s] = d;
      else
        qwe = a[s] == d ? 0 : 1;
    }
    if (qwe) {
      cout << -1 << endl;
      continue;
    }
    string asd = "";
    for (int i = 1; i <= q; i++) {
      if (a[i] == -1 && i == 1)
        a[i] = 1;
      else if (a[i] == -1)
        a[i] = 0;
      asd += a[i] + '0';
    }
    cout << asd << endl;
  }
}
