#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> d(n + 1, -1);
  bool err = false;
  while (m--) {
    int s, c;
    scanf("%d%d", &s, &c);
    if (d[s] == c) continue;
    if (d[s] == -1)
      d[s] = c;
    else
      err = true;
  }
  int num = 0, b = 1;
  for (int i = n; i >= 1; i--) {
    if (d[i] == -1) d[i] = 1;
    num += (d[i] * b);
    b *= 10;
  }
  int tmp = num, cnt = 0;
  while (tmp != 0) {
    tmp /= 10;
    ++cnt;
  }
  if (cnt < n && num > 0) err = true;
  if (err)
    puts("-1");
  else
    printf("%d\n", num);
  return 0;
}
