#include <bits/stdc++.h>
using namespace std;
char sm[4];
string out(int n) {
  if (sm[0] == '-') {
    return "-1";
  }
  string ans = "";
  for (int i = 0; i < n; i++) {
    ans += sm[i];
  }
  reverse(ans.begin(), ans.end());
  if (ans[0] == '0') {
    return "-1";
  } else {
    return ans;
  }
}
int main() {
  int m, n;
  cin >> m >> n;
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b += 48;
    if (sm[0] != '-') {
      if (sm[a] < 10) {
        if (sm[a] != b) {
          sm[0] = '-';
          sm[1] = '1';
        }
      } else {
        sm[a] = b;
      }
    }
  }
  if (sm[n - 1] < 10) {
    sm[n - 1] = '1';
  }
  for (int i = 0; i < n - 1; i++) {
    if (sm[i] < 10) {
      sm[i] = '0';
    }
  }
  string ans = out(n);
  cout << ans;
  return 0;
}
