#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int M, N;
  cin >> M >> N;
  int s[M];
  int c[M];
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  int u = 0;
  int check = 0;
  int num[3];
  for (int j = 100; j <= 999; j++) {
    num[0] = j / 100;
    num[1] = (j - num[0] * 100) / 10;
    num[2] = (j - num[0] * 100 - num[1] * 10);
    check = 0;
    for (int k = 0; k < M; k++) {
      if (num[s[k] - 1] == c[k]) {
        check += 1;
      }
    }
    if (check == M) {
      check = 1;
      u = j;
      break;
    } else {
      check = 0;
    }
  }
  if (check == 1) {
    cout << u << endl;
  } else {
    cout << -1 << endl;
  }
}
