#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, i, s, c, ans = 0, flag = 0;
  cin >> n >> m;
  int a[4] = {0};
  for (i = 1; i <= n; i++) {
    cin >> s >> c;
    if (a[s] != 0) flag = 1;
    a[s] = c;
  }
  if (a[1] == 0 && a[2] == 0 && a[3] == 0)
    cout << -1 << endl;
  else if (flag == 1)
    cout << -1 << endl;
  else {
    for (i = 1; i <= n; i++) {
      ans = ans * 10 + a[i];
    }
    cout << ans << endl;
  }
}
