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