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