#include <bits/stdc++.h>
using namespace std;
int n, m, s[9], c[9], d[9], ans;
bool ok[9];
int main() {
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> s[i] >> c[i];
    if (ok[s[i]] and c[i] != d[s[i]]) {
      cout << -1;
      return 0;
    }
    if (s[i] == 1 and c[i] == 0) {
      cout << -1;
      return 0;
    }
    d[s[i]] = c[i];
    ok[s[i]] = 1;
  }
  cout << d[1] * 100 + d[2] * 10 + d[3];
  return 0;
}
