#include <bits/stdc++.h>
using namespace std;
int n, m, d[5], c, s;
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; ++i) d[i] = -1;
  for (int i = 1; i <= m; ++i) {
    scanf("%d %d", &c, &s);
    if (d[c] != -1 && d[c] != s) {
      printf("-1");
      return 0;
    }
    d[c] = s;
  }
  if (d[1] == 0 && n != 1) {
    printf("-1");
    return 0;
  }
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    if (i == 1 && d[i] == -1) ans = 1;
    if (d[i] != -1)
      ans = ans * 10 + d[i];
    else
      ans = ans * 10;
  }
  printf("%d", ans);
}
