#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int A = 0;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    int keta = pow(10, N - s);
    if (s == 1 && c == 0 && N > 1) {
      cout << "-1";
      return 0;
    } else if (A / keta % 10 != 0 && A / keta % 10 != c) {
      cout << "-1";
      return 0;
    } else if (A / keta % 10 == 0) {
      A += keta * c;
    }
  }
  cout << A;
  return 0;
}
