#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> p(n + 1, vector<int>(0));
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    p[x].push_back(y);
  }
  for (int i = 1; i < n + 1; i++) {
    if (p[i].size() < 2) continue;
    for (int j = 0; j < p[i].size() - 1; j++) {
      if (p[i][j] != p[i][j + 1]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (p[1][0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i < n + 1; i++) {
    if (p[i].size() > 0)
      cout << p[i][0];
    else
      cout << 0;
  }
  cout << endl;
}
