#include <bits/stdc++.h>
using namespace std;
int main() {
  int first, second, third;
  first = second = third = -1;
  int n, m;
  scanf("%d%d", &n, &m);
  bool check = true;
  while (m--) {
    int a, b;
    scanf("%d%d", &a, &b);
    if (a == 1) {
      if (first != -1) {
        if (first != b) check = false;
      } else
        first = b;
    }
    if (a == 2) {
      if (second != -1) {
        if (second != b) check = false;
      } else
        second = b;
    }
    if (a == 3) {
      if (third != -1) {
        if (third != b) check = false;
      } else
        third = b;
    }
  }
  if (first == 0 || !check)
    puts("-1");
  else if (n == 1)
    printf("%d\n", first == -1 ? 0 : first);
  else if (n == 2) {
    printf("%d", first == -1 ? 1 : first);
    printf("%d\n", second == -1 ? 0 : second);
  } else if (n == 3) {
    printf("%d", first == -1 ? 1 : first);
    printf("%d", second == -1 ? 0 : second);
    printf("%d\n", third == -1 ? 0 : third);
  }
  return 0;
}
