#include <bits/stdc++.h>
const double eps = 1e-6;
const int INF = 0x3f3f3f3f;
const int N = 1e5 + 5;
using namespace std;
int t, n, m, x, y, z, flag = 0;
int a[N] = {0}, vis[N] = {0};
int main() {
  scanf("%d%d", &n, &m);
  while (m--) {
    scanf("%d%d", &x, &y);
    if (vis[x] == 0) {
      a[x] = y;
      vis[x] = 1;
    } else if (vis[x] == 1 && y != a[x]) {
      flag = 1;
    }
  }
  if (a[1] == 0 && n != 1 && vis[1] == 1) flag = 1;
  if (flag)
    printf("-1\n");
  else {
    if (vis[1] == 0)
      printf("1");
    else
      printf("%d", a[1]);
    for (int i = 2; i <= n; i++) {
      printf("%d", a[i]);
    }
    printf("\n");
  }
  return 0;
}
