#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  int m, i;
  int a[4];
  int flag = 0;
  int b, c;
  memset(a, -1, sizeof(a));
  scanf("%d%d", &n, &m);
  for (i = 0; i < m; i++) {
    scanf("%d%d", &b, &c);
    if (a[b] == -1) {
      a[b] = c;
    } else {
      if (a[b] != c) flag = 1;
    }
  }
  int cnt = 0;
  if (flag)
    printf("-1\n");
  else {
    if ((a[1] == 0) && n != 1)
      printf("-1\n");
    else if (a[1] == -1 && n == 1)
      printf("-1\n");
    else {
      for (i = 0; i < n; i++) {
        if (a[n - i] != -1)
          cnt += a[n - i] * pow(10, i);
        else {
          if (n - i == 1)
            a[1] = 1;
          else
            a[n - i] = 0;
          cnt += a[n - i] * pow(10, i);
        }
      }
      printf("%d\n", cnt);
    }
  }
  return 0;
}
