#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  bool ans = true;
  int ansnum = 0;
  vector<int> numbers(N);
  numbers.at(0) = 1;
  for (int i = 0; i < M; i++) {
    int si, ci;
    cin >> si >> ci;
    if (si == 1) {
      if (numbers.at(0) != ci) {
        if (numbers.at(0) != 1 || (N != 1 && ci == 0)) {
          ans = false;
          break;
        } else {
          numbers.at(0) = ci;
        }
      }
    } else {
      if (numbers.at(si - 1) != ci) {
        if (numbers.at(si - 1) != 0) {
          ans = false;
          break;
        } else {
          numbers.at(si - 1) = ci;
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    int kurai = 1;
    if (i > 0) {
      for (int j = 0; j < i; j++) {
        kurai *= 10;
      }
    }
    ansnum += kurai * numbers.at(N - i - 1);
  }
  if (ans) {
    cout << ansnum << endl;
  } else {
    cout << -1 << endl;
  }
}
