#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[10];
  char c[10];
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> c[i];
  }
  bool isok = false;
  int start[3] = {0, 10, 100};
  int end[3] = {9, 99, 999};
  int ans = -1;
  for (int i = start[n - 1]; i <= end[n - 1]; i++) {
    string str = to_string(i);
    bool isok = true;
    for (int j = 0; j < m; j++) {
      if (str[s[j] - 1] != c[j]) {
        isok = false;
        break;
      }
    }
    if (isok) {
      ans = i;
      break;
    }
  }
  cout << ans << endl;
  return 0;
}
