#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, k;
  bool f;
  cin >> n >> m;
  vector<int> x(n, -1);
  vector<int> s(m), c(m);
  f = true;
  for (i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    if (x.at(s.at(i) - 1) == -1)
      x.at(s.at(i) - 1) = c.at(i);
    else if (x.at(s.at(i) - 1) != c.at(i)) {
      f = false;
      break;
    }
  }
  if (f == false)
    cout << -1 << endl;
  else if (n >= 2 && x.at(0) == 0)
    cout << -1 << endl;
  else {
    k = 0;
    for (i = 0; i < n; i++) {
      if (x.at(i) == -1) {
        if (i == 0)
          x.at(i) = 1;
        else
          x.at(i) = 0;
      }
      k *= 10;
      k += x.at(i);
    }
    cout << k << endl;
  }
}
