#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
using vi = vector<int>;
using vii = vector<vi>;
int main() {
  int n, m;
  cin >> m >> n;
  vi a(5, 0);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    a[s - 1] = min(c, (a[s - 1] != 0 ? a[s - 1] : c));
  }
  int cnt = 0;
  for (int i = 0; i < m; i++) {
    if (a[i] != 0)
      break;
    else
      cnt++;
  }
  int ans = 0;
  int b = 0;
  if (m - cnt == n) {
    for (int i = m - 1; i >= cnt; i--) {
      ans += a[i] * pow(10, b);
      b++;
    }
    cout << ans << endl;
  } else
    cout << -1 << endl;
  return 0;
}
