#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = std::pair<int, int>;
using PLL = std::pair<ll, ll>;
const int mod = 1e9 + 7;
const string wsp = " ";
const string tb = "\t";
const string rt = "\n";
void showvec(vector<int> v) {
  for (int i = 0; i < (int)(v.size() - 1); i++) {
    cout << v[i] << wsp;
  }
  cout << v[v.size() - 1] << rt;
}
int main() {
  int n, m, x, y;
  cin >> n >> m;
  vector<int> num(n), status(n);
  fill((num).begin(), (num).end(), 0);
  fill((status).begin(), (status).end(), 0);
  bool ans = true;
  for (int i = 0; i < (int)(n); i++) {
    cin >> x >> y;
    x--;
    if (status[x] == 0) {
      num[x] = y;
      status[x]++;
    } else if (status[i] && num[x] != y)
      ans = false;
  }
  if (ans && (n == 0 || (n != 1 && num[0] != 0))) {
    for (int i = 0; i < (int)(n); i++) cout << num[i];
    cout << rt;
  } else {
    cout << -1 << rt;
  }
  return 0;
}
