#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  int* num = new int[n];
  for (int i = 0; i < n; i++) {
    num[i] = -1;
  }
  bool legal = true;
  for (int i = 0; i < m; i++) {
    int s, c;
    scanf("%d %d", &s, &c);
    s -= 1;
    if (num[s] == -1 || num[s] == c) {
      num[s] = c;
    } else {
      legal = false;
    }
  }
  if (num[0] == 0 && n != 1) legal = false;
  if (num[0] == -1) num[0] = 1;
  if (legal) {
    for (int i = 0; i < n; i++) {
      if (num[i] == -1) num[i] = 0;
      printf("%d", num[i]);
    }
  } else {
    printf("-1");
  }
}
