#include <bits/stdc++.h>
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  int a[m][2], b[n];
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &a[i][0], &a[i][1]);
  }
  for (int i = 0; i < n; i++) b[i] = 0;
  int ans = 0;
  for (int i = 0; i < m; i++) {
    if (b[a[i][0] - 1] == 0)
      b[a[i][0] - 1] = a[i][1];
    else {
      if (b[a[i][0] - 1] == a[i][1])
        continue;
      else
        ans = -1;
    }
  }
  if (b[0] == 0) ans = -1;
  if (ans == -1)
    printf("-1\n");
  else {
    for (int i = 0; i < n; i++) printf("%d", b[i]);
    printf("\n");
  }
  return 0;
}
