#include <bits/stdc++.h>
using namespace std;
int pow(int a, int b) {
  int aa = 1;
  for (int i = 0; i < b; i++) aa *= a;
  return aa;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) cin >> s.at(i) >> c.at(i);
  int number = 0;
  int digit;
  int dignum;
  for (int i = 0; i < M; i++) {
    digit = pow(10, (N - s.at(i)));
    dignum = (number % (digit * 10)) / digit;
    number -= (digit * dignum);
    number += (digit * c.at(i));
  }
  if (number / pow(10, (N - 1)) == 0) number += pow(10, (N - 1));
  for (int i = 0; i < (M - 1); i++) {
    for (int j = i + 1; j < M; j++) {
      if (s.at(i) == s.at(j)) {
        if (c.at(i) != c.at(j)) number = -1;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (s.at(i) == 1) {
      if (c.at(i) == 0) number = -1;
    }
  }
  cout << number << endl;
}
