#include <bits/stdc++.h>
using namespace std;
const long long INF = numeric_limits<long long>::max();
int main() {
  int n;
  scanf("%d", &n);
  int m;
  scanf("%d", &m);
  vector<int> s(m);
  vector<int> c(m);
  for (int i = 0; i < (int)(m); i++) {
    scanf("%d", &(s.at(i)));
    scanf("%d", &(c.at(i)));
  }
  vector<int> numbers(n);
  for (int i = 0; i < (int)(n); i++) {
    numbers.at(i) = -1;
  }
  bool impossible = false;
  for (int i = 0; i < (int)(m); i++) {
    if (numbers.at(s.at(i) - 1) == -1) {
      numbers.at(s.at(i) - 1) = c.at(i);
    } else {
      if (numbers.at(s.at(i) - 1) != c.at(i)) {
        impossible = true;
        break;
      }
    }
  }
  if (numbers.at(0) == -1) {
    numbers.at(0) = 1;
  }
  for (int i = 1; i < (int)(n); i++) {
    if (numbers.at(i) == -1) {
      numbers.at(i) = 0;
    }
  }
  if (numbers.at(0) == 0) {
    impossible = true;
  }
  int value = 0;
  if (!impossible) {
    value = 0;
    for (int i = 0; i < (int)(n); i++) {
      value = numbers.at(i) + value * 10;
    }
  } else {
    value = -1;
  }
  printf("%d\n", value);
  return 0;
}
