#include <bits/stdc++.h>
using namespace std;
using p = pair<long long, long long>;
long long dx[4] = {1, 0, -1, 0};
long long dy[4] = {0, 1, 0, -1};
int main(void) {
  long long n, m;
  cin >> n >> m;
  long long s[m];
  char c[m];
  for (long long i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  bool check = true;
  for (long long i = 1; i < 1000; i++) {
    string a = to_string(i);
    check = true;
    for (long long j = 0; j < m; j++) {
      long long d = s[j] - 1;
      if (a[d] != c[j]) check = false;
    }
    if (check == true) {
      cout << i << endl;
      break;
    }
    if (check == false && i == 999) cout << -1 << endl;
  }
  return 0;
}
