#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  std::cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  char n[3];
  for (int i = 0; i < 3; i++) {
    n[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    if (s[i] > 3) {
      printf("-1\n");
      return 0;
    } else if (n[s[i] - 1] != 0 && n[s[i] - 1] != c[i] + '0') {
      printf("-1\n");
      return 0;
    }
    n[s[i] - 1] = c[i] + '0';
  }
  for (int i = 0; i < 3; i++) {
    if (n[i] == 0) {
      n[i] = '0';
    }
  }
  if (n[0] == '0') {
    printf("-1\n");
    return 0;
  }
  for (int i = 0; i < 3; i++) {
    printf("%c", n[i]);
  }
  printf("\n");
  return 0;
}
