#include <bits/stdc++.h>
using namespace std;
const long long siz = 1e6 + 10;
const long long mod = 1e9 + 7;
const long long MAXX = 1e17;
const long long base = 31;
long long n, m;
long long num[5];
bool check[5];
long long s, c;
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (long long i = 1; i <= 5; i++) check[i] = false;
  cin >> n >> m;
  for (long long i = 1; i <= n; i++) {
    cin >> s >> c;
    if (num[s] == c || (num[s] == 0 && check[s] == false)) {
      num[s] = c;
      check[s] = true;
    } else {
      cout << "-1";
      return 0;
    }
  }
  if (num[1] == 0) {
    cout << "-1";
    return 0;
  }
  for (long long i = 1; i <= n; i++) cout << num[i];
  return 0;
}
