#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, a = 0, x, y;
  cin >> N >> M;
  vector<int> used(3, 0);
  for (int i = 0; i < (int)M; i++) {
    cin >> x >> y;
    if (N > 1 && x == 1 && y == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (used.at(x - 1) != 0 && used.at(x - 1) != y) {
      cout << -1 << endl;
      return 0;
    }
    if (used.at(x - 1) == 0) a += pow(10, N - x) * y;
    used.at(x - 1) = y;
  }
  if (pow(10, N - 1) > a) a += pow(10, N - 1);
  cout << a << endl;
}
