#include <bits/stdc++.h>
using namespace std;
const long long mod = 1e9 + 7;
const int sz = 500;
int main() {
  int n, m;
  cin >> n >> m;
  vector<pair<int, int> > vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec[i].first >> vec[i].second;
  }
  string str = "";
  str.append(m, 'a');
  for (auto x : vec) {
    str[x.first - 1] = (x.second + '0');
  }
  bool flag = true;
  sort(vec.begin(), vec.end());
  for (int i = 1; i < vec.size(); i++) {
    if (vec[i].first == vec[i - 1].first &&
        vec[i].second != vec[i - 1].second) {
      flag = false;
      break;
    }
  }
  for (int i = 0; i < (int)str.size(); i++) {
    if (i == 0 && (str[i] == 'a' || str[i] == '0')) {
      flag = false;
      break;
    } else if (str[i] == 'a')
      str[i] = '0';
  }
  if (!flag)
    puts("-1");
  else
    cout << str << endl;
  return 0;
}
