#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 ans = 0;
  bool guess = true;
  for (int i = 0; i < M; i++) {
    if (s.at(i) == 1 && c.at(i) == 0) {
      guess = false;
      break;
    }
    for (int j = i; j < M; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        guess = false;
        break;
      }
    }
  }
  vector<int> answer(N);
  answer.at(0) = 1;
  for (int i = 1; i < N; i++) {
    answer.at(i) = 0;
  }
  for (int j = 0; j < N; j++) {
    for (int i = 0; i < M; i++) {
      if (s.at(i) == j + 1) {
        answer.at(j) = c.at(i);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    ans += answer.at(i) * pow(10, N - i - 1);
  }
  if (guess) {
    cout << ans << endl;
  } else {
    cout << -1 << endl;
  }
}
