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