#include <iostream>
#include <cmath>

int main() {
  int N, M, i, j;
  std::cin >> N >> M;
  
  int s[M], c[M];
  for (i = 0; i < M; i++) {
    std::cin >> s[i] >> c[i];
  }
  
  int A[N][2] = {};
  int B = 0;
  for (i = 0; i < N; i++) {
    for (j = 0; j < M; j++) {
      if (s[j]-1 == i) {
        if (A[i][0] == 0) {
          A[i][0] = 1;
          A[i][1] = c[j];
        } else {
          if (A[i][1] != c[j]) {
            B = -1;
            i = N;
            j = M;
          }
        }
      }
    }
  }
  
  if (B == 0) {
    for (i = 0; i < N; i++) {
      if (A[i][0] == 0) {
        B += std::pow(10, N-i-1);
      } else {
        if (A[0][1] == 0) {
          B = -1;
          break;
        }
        B += A[i][1] * std::pow(10, N-i-1);
      }
    }
  }
  std::cout << B << std::endl;
  return 0;
}