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