#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n, 0);
  for (int i = 0; i < n; i++) {
    int s, c;
    cin >> s >> c;
    a[s - 1] = c;
  }
  if (a[0] == 0) {
    cout << -1 << endl;
  } else {
    int num = 0;
    int ten = 1;
    reverse(a.begin(), a.end());
    for (int i = 0; i < n; i++) {
      num = num + (a[i] * ten);
      ten = ten * 10;
    }
    cout << num << endl;
  }
}
