#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, flg(0);
  cin >> n >> m;
  vector<int> a(n), s(m), c(m);
  for (int i = 0; i < n; i++) {
    a.at(i) = -1;
  }
  for (int i = 0; i < m; i++) {
    cin >> s.at(i) >> c.at(i);
    if (a.at(s.at(i) - 1) == -1) {
      a.at(s.at(i) - 1) = c.at(i);
    } else if (a.at(s.at(i) - 1) != c.at(i)) {
      flg = 1;
      break;
    }
  }
  if (flg == 1 || (a.at(0) == 0 && n != 1)) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < n; i++) {
      if (a.at(i) == -1) a.at(i) = 0;
      cout << a.at(i);
    }
    cout << endl;
  }
}
