#include <bits/stdc++.h>
using namespace std;
int mas[3] = {-1, -1, -1};
int main() {
  int n, m;
  cin >> n >> m;
  while (m--) {
    int a, b;
    cin >> a >> b;
    if (mas[a - 1] != -1) {
      cout << -1 << '\n';
      return 0;
    }
    mas[a - 1] = b;
  }
  for (int i = 0; i <= 999; i++) {
    if (to_string(i).size() != n) continue;
    string str = to_string(i);
    bool fnd = true;
    for (int j = 0; j < str.size(); j++) {
      if (mas[j] == -1) continue;
      if (str[j] - '0' != mas[j]) fnd = false;
    }
    if (fnd) {
      cout << i << '\n';
      return 0;
    }
  }
  cout << -1 << '\n';
  return 0;
}
