#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e+18 + 1;
const long long MOD = 1000000007LL;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main() {
  long long n, m;
  cin >> n >> m;
  vector<map<long long, long long> > Mvec(n);
  for (long long i = 0; i < (long long)(n); i++) {
    long long s, c;
    cin >> s >> c;
    Mvec[s - 1][c]++;
  }
  vector<long long> vec(n);
  vec[0] = 1;
  if (n == 1) vec[0] = 0;
  bool ans = true;
  for (long long i = 0; i < (long long)(m); i++) {
    long long count = 0;
    for (auto p : Mvec[i]) {
      if (i == 0 && p.first == 0) {
        if (p.second != 0) ans = false;
      }
      vec[i] = p.first;
      count++;
    }
    if (count > 1) ans = false;
  }
  if (ans) {
    for (long long i = 0; i < (long long)(n); i++) cout << vec[i];
    cout << endl;
  } else
    cout << -1 << endl;
}
