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