#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[6], c[6];
int t[10];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &s[i], &c[i]);
    if (t[s[i]] != 0 && t[s[i]] != c[i]) {
      cout << -1;
      exit(0);
    }
    t[s[i]] = c[i];
  }
  if (n == 1 && t[1] == 0) {
    printf("0\n");
    exit(0);
  }
  bool first = 1;
  for (int i = 1; i <= n; i++) {
    if (first && t[first] == 0) {
      cout << -1;
      exit(0);
    }
    first = 0;
    printf("%d", t[i]);
  }
  return 0;
}
