#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> s(m);
  vector<char> c(m);
  for (int i = 0; i < n; i++) cin >> s[i] >> c[i];
  int ans = -1;
  bool exist = true;
  if (n == 1) {
    for (int num = 0; num <= 9; num++) {
      string str = to_string(num);
      for (int i = 0; i < m; i++) {
        if (exist == true && str[s[i] - 1] == c[i])
          exist = true;
        else {
          exist = false;
          break;
        }
      }
      if (exist) {
        ans = num;
        break;
      }
    }
  } else if (n == 2) {
    for (int num = 10; num <= 99; num++) {
      string str = to_string(num);
      for (int i = 0; i < m; i++) {
        if (exist == true && str[s[i] - 1] == c[i])
          exist = true;
        else {
          exist = false;
          break;
        }
      }
      if (exist) {
        ans = num;
        break;
      }
    }
  } else {
    for (int num = 100; num <= 999; num++) {
      string str = to_string(num);
      for (int i = 0; i < m; i++) {
        if (exist == true && str[s[i] - 1] == c[i])
          exist = true;
        else {
          exist = false;
          break;
        }
      }
      if (exist) {
        ans = num;
        break;
      }
    }
  }
  cout << ans << endl;
  return 0;
}
