#include <bits/stdc++.h>
using namespace std;
const int N = 1 * 1e6 + 5;
const unsigned long long mod = 1e9 + 7;
const int INF = INT_MAX;
const unsigned long long INFCAD = unsigned long long(INT_MAX) * 2 + 1;
const double E = 1e-9;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
int POW(int a, int b) {
  int ans = 1;
  while (b) {
    if (b & 1) ans *= a;
    a *= a;
    b >>= 1;
  }
  return ans;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m;
  cin >> n >> m;
  int v[n + 2];
  memset(v, -1, sizeof(v));
  bool flag = 1;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    if (v[x] == -1)
      v[x] = y;
    else {
      if (v[x] != y) flag = 0;
    }
  }
  if (flag) {
    for (int i = POW(10, n - 1); i <= POW(10, n) - 1; i++) {
      string nm = to_string(i);
      bool sw = 1;
      for (int j = 0; j < int(nm.size()); j += 1) {
        if (v[j] != -1) {
          if (v[j] != nm[j] - '0') {
            sw = 0;
            break;
          }
        }
      }
      if (sw) {
        cout << i << '\n';
        return 0;
      }
    }
    cout << -1 << '\n';
  } else
    cout << "-1\n";
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
  return 0;
}
