#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  if (M == 0) {
    if (N == 1) cout << 0 << endl;
    if (N == 2) cout << 10 << endl;
    if (N == 3) cout << 100 << endl;
    return 0;
  }
  vector<pair<int, char>> A(M);
  for (int i = 0; i < M; i++) {
    cin >> A[i].first >> A[i].second;
  }
  vector<int> ten = {0, 10, 100, 1000};
  int check = 0;
  for (int i = 0; i < 1000; i++) {
    check = 0;
    string s = to_string(i);
    if (i >= 700 && i < ten[N]) {
      check = 1;
      for (int j = 0; j < M; j++) {
        if (s[A[j].first - 1] != A[j].second) {
          check = 2;
        }
      }
    }
    if (check == 1) {
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}
