#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int s, c;
  int p[3] = {0};
  bool q[3] = {0}, flag = 0;
  for (; m > 0; m--) {
    scanf("%d %d", &s, &c);
    if (p[3 - s] == c || q[3 - s] == 0) {
      p[3 - s] = c;
      q[3 - s] = 1;
    } else {
      flag = 1;
      break;
    }
  }
  if (flag || p[2] == 0)
    printf("%d", -1);
  else
    printf("%d", p[2] * 100 + p[1] * 10 + p[0]);
  return 0;
}
