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