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