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