#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> vec(3, -1);
  for (int i = 0; i < n; i++) {
    int d, v;
    cin >> d >> v;
    if (vec[d - 1] != -1) {
      cout << -1 << endl;
      return 0;
    }
    vec[d - 1] = v;
  }
  if (n != 1 && vec[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  int k = n - 1;
  for (int i = 0; i < n; i++) {
    int v = vec[i] != -1 ? vec[i] : (i == 0 ? 1 : 0);
    ans += v * pow(10, k);
    k--;
  }
  cout << ans << endl;
  return 0;
}
