#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  vector<int> resultNum(N, -1);
  int result = 0;
  for (int i = 0; i < M; i++) {
    if (resultNum.at((s.at(i)) - 1) == -1 ||
        resultNum.at((s.at(i)) - 1) == c.at(i)) {
      resultNum.at((s.at(i)) - 1) = c.at(i);
    } else {
      result = -1;
    }
  }
  if (resultNum.at(0) == 0 && N != 1) {
    result = -1;
  }
  if ((resultNum.at(0) == -1) && result != -1) {
    for (int i = 1; i < N; i++) {
      if (resultNum.at(i) != -1) {
        resultNum.at(0) = 1;
        break;
      }
    }
    if (resultNum.at(0) == 0 || resultNum.at(0) == -1) {
      result = -1;
    }
  }
  if (result != -1) {
    for (int i = 0; i < N; i++) {
      if (resultNum.at(N - 1 - i) == -1) {
        resultNum.at(N - 1 - i) = 0;
      }
      result += resultNum.at(N - 1 - i) * pow(10, i);
    }
  }
  cout << result << endl;
}
