#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  bool nonumber = 0;
  cin >> N >> M;
  vector<long long> s(M), c(M), number(N, 0);
  for (long long i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    number.at(s.at(i) - 1) = c.at(i);
    for (long long j = 0; j < i; j++) {
      if ((s.at(i) == s.at(j)) && (c.at(i) != c.at(j))) nonumber = 1;
    }
    if ((s.at(i) == 1) && (c.at(i) == 0) && (N != 1)) nonumber = 1;
  }
  if (nonumber == 1)
    cout << -1 << endl;
  else {
    for (long long i = 0; i < N; i++) {
      if ((i == 0) && (number.at(i) == 0))
        cout << 1;
      else
        cout << number.at(i);
    }
  }
}
