#include <bits/stdc++.h>
using namespace std;
int main(int argc, char **argv) {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  for (int i = 0; i < n; i++) {
    int b, c;
    cin >> b >> c;
    if (b == 1 && c == 0) {
      cout << -1;
      return 0;
    }
    if (a[b - 1] == -1) {
      a[b - 1] = c;
    } else {
      if (a[b - 1] != c) {
        cout << -1;
        return 0;
      }
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == -1) {
      cout << 0;
    } else {
      cout << a[i];
    }
  }
}
