#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  if (m > n) {
    cout << -1 << endl;
    return 0;
  }
  vector<int> vec(n, -1);
  for (int i = 0; i < m; i++) {
    int pos, num;
    cin >> pos >> num;
    if (vec[pos - 1] != -1 && vec[pos - 1] != num) {
      cout << -1 << endl;
      return 0;
    }
    vec[pos - 1] = num;
  }
  string ans = "";
  for (int i = 0; i < n; i++) {
    if (i == 0 && vec[0] == -1 && n == 1) {
      cout << 0 << endl;
      return 0;
    } else if (i == 0 && vec[0] == -1) {
      ans += "1";
    }
    if (vec[i] == -1) {
      ans += "0";
    } else {
      ans += to_string(vec[i]);
    }
  }
  int res = stoi(ans);
  if (to_string(res).length() != n) {
    cout << -1 << endl;
  } else
    cout << res << endl;
  return 0;
}
