#include <bits/stdc++.h>
int main() {
  int n, m, i, j, k;
  int a = 10, b = 10, c = 10;
  int z = 0;
  int s[10][2];
  scanf("%d %d", &n, &m);
  if (m != 0) {
    for (i = 0; i < m; i++) {
      scanf("%d %d", &s[i][0], &s[i][1]);
    }
  }
  for (i = 0; i < m; i++) {
    if (s[i][0] == 1) {
      if (s[i][1] == 0 && n != 1) {
        printf("-1");
        return 0;
      }
      if (s[i][1] != a) {
        printf("-1");
        return 0;
      } else if (a == 10) {
        a = s[i][1];
        z = z + a * 100;
      }
    }
    if (s[i][0] == 2) {
      if (s[i][1] != b) {
        printf("-1");
        return 0;
      } else if (b == 10) {
        b = s[i][1];
        z = z + b * 10;
      }
    }
    if (s[i][0] == 3) {
      if (s[i][1] != c) {
        printf("-1");
        return 0;
      } else if (c == 10) {
        c = s[i][1];
        z = z + c;
      }
    }
  }
  printf("%d", z);
  return 0;
}
