#include <bits/stdc++.h>
using namespace std;
long long gcd(long x, long y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long lcm(long x, long y) { return x * y / gcd(x, y); }
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
int main() {
  int N, M, s, c, ansA = -1, ansB = -1, ansC = -1;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) {
    cin >> s >> c;
    if (s == 1) {
      if (ansA != -1 && ansA != c) {
        cout << -1 << endl;
        return 0;
      }
      ansA = c;
    } else if (s == 2) {
      if (ansB != -1 && ansB != c) {
        cout << -1 << endl;
        return 0;
      }
      ansB = c;
    } else {
      if (ansC != -1 && ansC != c) {
        cout << -1 << endl;
        return 0;
      }
      ansC = c;
    }
  }
  if (ansA == -1) {
    if (N > 1) {
      ansA = 1;
    } else {
      ansA = 0;
    }
  }
  if (ansB == -1) ansB = 0;
  if (ansC == -1) ansC = 0;
  if (ansA == 0 && N >= 2) {
    cout << -1 << endl;
    return 0;
  }
  if (N == 3) {
    cout << ansA * 100 + ansB * 10 + ansC << endl;
  } else if (N == 2) {
    cout << ansA * 10 + ansB << endl;
  } else {
    cout << ansA << endl;
  }
  return 0;
}
