#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int n, m;
  cin >> n >> m;
  int d[] = {-1, -1, -1};
  for (decltype(m) i = 0; i < (m); i++) {
    int digit, value;
    cin >> digit >> value;
    if ((d[n - digit] != -1 and d[n - digit] != value) or
        (n != 1 and digit == 1 and value == 0)) {
      cout << -1 << endl;
      return 0;
    }
    d[n - digit] = value;
  }
  if (d[n - 1] == -1 or d[n - 1] == 0) d[n - 1] = 1;
  int res = 0;
  int temp = 1;
  for (decltype(n) i = 0; i < (n); i++) {
    if (d[i] != -1) res += d[i] * temp;
    temp *= 10;
    if (i == 0 and n == 1) {
      cout << 0 << endl;
    }
    cout << res << endl;
    return 0;
  }
}
