#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  long long ans = 0;
  long long n, m;
  cin >> n >> m;
  vector<long long> numbers(n);
  for (long long i = (0); i < (n); i++) {
    numbers[i] = 0;
  }
  long long keta;
  long long number;
  for (long long i = (0); i < (m); i++) {
    cin >> keta >> number;
    if (numbers[keta - 1] != 0 && numbers[keta - 1] != number) {
      cout << -1 << endl;
      return 0;
    }
    if (numbers[keta - 1] != 0 && numbers[keta - 1] == number) {
      continue;
    }
    if (numbers[keta - 1] == 0) {
      numbers[keta - 1] = number;
      continue;
    }
  }
  if (numbers[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = (0); i < (n); i++) {
    ans += numbers[i] * (pow(10, n - 1 - i));
  }
  cout << ans << endl;
  return 0;
}
