#include <bits/stdc++.h>
using namespace std;
unsigned GetDigit(unsigned num) {
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(N);
  vector<char> c(N);
  for (int i = 0; i < N; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int ans = 0;
  bool AA = false;
  for (int i = 0; i < 1000; i++) {
    string str = to_string(i);
    if (GetDigit(i) == N) {
      for (int j = 0; j < M; j++) {
        if (str.at(s.at(j)) == c.at(j)) {
          AA = true;
          ans = i;
          goto DEF;
        }
      }
    }
  }
DEF:
  if (AA == true) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
