#include <bits/stdc++.h>
using namespace std;
void Yes() { printf("Yes\n"); }
void No() { printf("No\n"); }
const long long mod = 1e9 + 7;
template <typename T>
T gcf(T a, T b) {
  return (b == 0) ? a : gcf(b, a % b);
}
template <typename T>
T lcm(T a, T b) {
  return (a * b) / gcf(a, b);
}
template <typename T>
T sumTo(T x) {
  return x * (x + 1) / 2;
}
template <typename T>
T sumSquaresTo(T x) {
  return x * (x + 1) * (2 * x + 1) / 6;
}
template <typename T>
T ceilDiv(T n, T d) {
  return (n + d - 1) / d;
}
int n, m;
set<pair<int, int> > restrictions;
int numDigits(int x) {
  int ans = 0;
  while (x) {
    ans++;
    x /= 10;
  }
  return ans;
}
int digit(int x, int k) {
  k = numDigits(x) - k;
  for (int i = 0; i < k; i++) x /= 10;
  return x % 10;
}
bool works(int ans) {
  if (numDigits(ans) != n) return false;
  for (pair<int, int> x : restrictions) {
    int s = x.first;
    int c = x.second;
    if (digit(ans, s) != c) return false;
  }
  return true;
}
void solve() {
  scanf("%d", &n);
  scanf("%d", &m);
  int s, c;
  for (int i = 0; i < n; i++) {
    scanf("%d", &s);
    scanf("%d", &c);
    restrictions.insert(make_pair(s, c));
  }
  for (int ans = 1; ans <= 999; ans++) {
    if (works(ans)) {
      printf("%d ", ans);
      return;
    }
  }
  printf("%d ", -1);
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
