#include <bits/stdc++.h>
using namespace std;
int a[5];
int main() {
  int n, m;
  while (~scanf("%d %d", &n, &m)) {
    memset(a, 0X3f3f3f3f, sizeof a);
    int flag = 0;
    while (m--) {
      int x, y;
      scanf("%d %d", &x, &y);
      a[x] = min(a[x], y);
    }
    if ((n != 1 && a[1] == 0) || a[1] == 0X3f3f3f3f) flag = 1;
    if (flag)
      printf("-1\n");
    else {
      for (int i = 1; i <= n; i++)
        if (a[i] != 0X3f3f3f3f)
          printf("%d", a[i]);
        else
          printf("0");
      printf("\n");
    }
  }
  return 0;
}
