#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int k = 0; k < 1000; k++) {
    string K = to_string(k);
    for (int i = 0; i < M; i++) {
      if (s.at(i) == 2 && k < 10) goto next;
      if (s.at(i) == 3 && k < 100) goto next;
      if (K.at(s.at(i) - 1) != c.at(i)) goto next;
      if (N == 1 && k >= 10) goto next;
      if (N == 2 && (k < 10 || k >= 100)) goto next;
      if (N == 3 && k < 100) goto next;
    }
    cout << k << endl;
    return 0;
  next:
    continue;
  }
  cout << "-1" << endl;
}
