#include <bits/stdc++.h>
using namespace std;
const long long INF = 1LL << 60;
long long GCD(long long x, long long y) {
  if (y == 0)
    return x;
  else
    return GCD(y, x % y);
}
long long LCM(long long a, long long b) { return a / GCD(a, b) * b; }
const int MOD = 1000000007;
int main() {
  int n, m;
  cin >> n >> m;
  multimap<int, int> s;
  for (int i = 0; i < n; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    if (x == 0 && y == 0) {
      cout << -1;
      return 0;
    }
    to_string(x);
    to_string(y);
    auto z = s.find(x);
    if (z == s.end()) {
      s.insert(make_pair(x, y));
    } else {
      if (z->second == y) {
        continue;
      } else {
        cout << -1;
        return 0;
      }
    }
  }
  int ans = -1;
  for (int i = 1; i <= 999; i++) {
    string a = to_string(i);
    if (a.length() != n) continue;
    bool flag = true;
    for (auto b : s) {
      if (a[b.first] - '0' != b.second) {
        flag = false;
      }
    }
    if (flag) {
      ans = i;
      break;
    }
  }
  cout << ans;
}
