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