#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  int M;
  cin >> M;
  vector<int> Num(N, 0);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s;
    cin >> c;
    if (Num.at(N - s) == 0) {
      Num.at(N - s) = c;
    } else if (Num.at(N - s) != c) {
      Num.at(N - s) = -2;
    }
  }
  int answerNum = 0;
  for (int i = 0; i < N; i++) {
    if (Num.at(i) == -2) {
      answerNum = -1;
      break;
    }
    answerNum += Num.at(i) * pow(10, i);
  }
  bool flag = true;
  if (N != 1) {
    for (int i = 0; i < N; i++) {
      if (int(answerNum / pow(10, N - i - 1)) == 0) {
        flag = false;
        break;
      }
    }
  }
  if (flag == false) {
    answerNum = -1;
  }
  cout << answerNum << endl;
  return 0;
}
