#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;
}
const int MAXN = 15;
int n, m, a[MAXN];
void solve() {
  scanf("%d", &n);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) a[i] = 0;
  int s, c;
  for (int i = 0; i < n; i++) {
    cin >> s >> c;
    if (a[s] && a[s] != c) {
      printf("%d ", -1);
      return;
    }
    a[s] = c;
  }
  if (n > 1 && !a[1]) {
    printf("%d ", -1);
    return;
  }
  for (int i = 1; i <= n; i++) cout << a[i];
}
int main() {
  int t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
