#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  int jud = 0;
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        jud++;
      } else if (s.at(i) == s.at(j) && c.at(i) == c.at(j)) {
        s.at(j) = 0;
        c.at(j) = 0;
      } else {
        continue;
      }
    }
  }
  for (int i = 0; i < M; i++) {
    if (N != 1 && s.at(i) == 1 && c.at(i) == 0) {
      jud++;
    } else {
      continue;
    }
  }
  int x = 0;
  if (jud > 0) {
    cout << -1 << endl;
  } else {
    for (int i = 0; i < M; i++) {
      x += std::pow(10, N - s.at(i)) * c.at(i);
    }
    if (x == 0 && N == 3) {
      x = 100;
    } else if (x == 0 && N == 2) {
      x = 10;
    }
    cout << x << endl;
  }
}
