#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, tmp1, tmp2, flag = 1;
  cin >> n >> m;
  vector<int> vec(n);
  map<int, int> mp;
  for (int i = 0; i < n; i++) {
    cin >> tmp1 >> tmp2;
    if (mp.count(tmp1)) {
      if (tmp2 != vec.at(tmp1 - 1)) {
        flag = 0;
        break;
      }
    }
    mp[tmp1] = 1;
    vec.at(tmp1 - 1) = tmp2;
  }
  if (mp[1] == 1 && vec.at(0) == 0) flag = 0;
  if (!flag)
    cout << -1 << endl;
  else {
    for (int i = 0; i < n; i++) cout << vec.at(i);
    cout << endl;
  }
}
