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