#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  vector<int> s(n, 0);
  for (int i = 0; i < (n); i++) {
    int ind, num;
    if (ind == 1 && num == 0) {
      cout << -1 << endl;
      return 0;
    }
    cin >> ind >> num;
    if (s[n - ind] != 0 && s[n - ind] != num) {
      cout << -1 << endl;
      return 0;
    }
    s[n - ind] = num;
  }
  int ans = 0;
  for (int i = 0; i < (n); i++) {
    ans += s[i] * pow(10, i);
  }
  cout << ans << endl;
  return 0;
}
