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