#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[] = {0, 0, 0};
  for (decltype(m) i = 0; i < (m); i++) {
    int digit, value;
    cin >> digit >> value;
    digit--;
    if (d[digit] != 0 and d[digit] != value) {
      cout << -1 << endl;
      return 0;
    }
    if (n != 1 and digit == 0 and value == 0) {
      cout << -1 << endl;
      return 0;
    }
    d[digit] = value;
  }
  if (d[0] == 0) d[0] = 1;
  int res = 0;
  for (decltype(n) i = 0; i < (n); i++) {
    if (d[i] == -1)
      res = res * 10;
    else
      res = res * 10 + d[i];
  }
  cout << res << endl;
  return 0;
}
