#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> c(m);
  vector<int> s(m);
  vector<int> a(m);
  for (int i = 0; i < m; i++) {
    a[i] = 0;
  }
  for (int i = 0; i < n; i++) {
    cin >> s[i] >> c[i];
    if (s[i] > 0 && s[i] <= m) {
      if (a[s[i] - 1] != 0 && a[s[i] - 1] != c[i]) {
        puts("ここ");
        cout << -1 << endl;
        return 0;
      }
      a[s[i] - 1] = c[i];
    } else {
      puts("ここ1");
      cout << -1 << endl;
      return 0;
    }
  }
  if (a[0] == 0) {
    if (n == 1) {
      puts("0");
    } else {
      puts("ここ2");
      puts("-1");
    }
    return 0;
  }
  for (int i = 0; i < n; i++) {
    cout << a[i];
  }
  puts("");
  return 0;
}
