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