#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (a % b == 0)
    return b;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a * b / gcd(a, b); }
bool isPrime(long long x) {
  int i;
  if (x < 2)
    return false;
  else if (x == 2)
    return true;
  if (x % 2 == 0) return false;
  for (i = 3; i * i <= x; i += 2)
    if (x % i == 0) return false;
  return true;
}
int main() {
  int n, m, a;
  bool sw = true;
  a = -1;
  cin >> n >> m;
  int s[m][2];
  for (int i = 0; i < n; i++) {
    cin >> s[i][0] >> s[i][1];
  }
  for (int i = 0; i < pow(10, n); i++) {
    for (int j = 0; j < m; j++) {
      if (s[j][0] == 1 && (s[j][1] != i / 100 || i < 100)) sw = false;
      if (s[j][0] == 3 && s[j][1] != i % 10) sw = false;
      if (s[j][0] == 2 && (s[j][1] != (i / 10) % 10 || i < 10)) sw = false;
    }
    if (sw) {
      a = i;
      break;
    }
    sw = true;
  }
  cout << a << endl;
}
