#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
int main() {
  int N, M;
  cin >> N >> M;
  vi s(M);
  vector<char> c(M);
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  bool ISexist;
  int minnum = -1;
  int N0 = pow(10, N - 1);
  int N1 = pow(10, N);
  for (int i = N0; i < N1; i++) {
    ISexist = true;
    string str = to_string(i);
    for (int j = 0; j < M; j++) {
      if (str.at(s[j] - 1) != c[j]) {
        ISexist = false;
        break;
      }
    }
    if (ISexist) {
      minnum = i;
      break;
    }
  }
  cout << minnum << endl;
}
