#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int digits[3] = {0, 0, 0};
  bool ok = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (digits[s - 1] != 0 && digits[s - 1] != c) {
      ok = false;
    }
    digits[s - 1] = c;
  }
  if (ok) {
    if (N != 1 && digits[0] == 0)
      cout << -1;
    else {
      int sum = 0;
      for (int i = 0; i < N; i++) sum = sum * 10 + digits[i];
      cout << sum;
    }
  }
  return 0;
}
