#include <bits/stdc++.h>
using namespace std;
int main() {
  int64_t n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  bool flag = false;
  for (int64_t i = 0; i < (int64_t)(n); i++) {
    int s, c;
    cin >> s >> c;
    if (((n != 1) && (s == 1 && c == 0)) || (a[s - 1] != -1 && a[s - 1] != c)) {
      flag = true;
    } else {
      a[s - 1] = c;
    }
  }
  for (int64_t i = 0; i < (int64_t)(n); i++) {
    if (a[i] == -1) {
      if (i == 0) {
        a[i] = 1;
      } else {
        a[i] = 0;
      }
    }
  }
  if (flag) {
    cout << -1 << endl;
  } else {
    for (int64_t i = 0; i < (int64_t)(n); i++) {
      cout << a[i];
    }
    cout << endl;
  }
}
