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