#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  int a[3] = {-1, -1, -1};
  for (int i = 0; i < (n); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] != -1 && a[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    a[s] = c;
  }
  for (int i = 0; i < (3); i++)
    if (a[i] == -1) a[i] = 0;
  int ans = a[0] * 100;
  ans += a[1] * 10;
  ans += a[2];
  if (ans)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
