#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M, count = 0, ans = 0;
  string D, E;
  cin >> N >> M;
  vector<pair<int, int> > tasks(M);
  vector<int> A(N);
  for (int i = 0; i < (int)(N); i++) {
    A.at(i) = 0;
  }
  for (int i = 0; i < (int)(M); i++) {
    cin >> tasks.at(i).first >> tasks.at(i).second;
  }
  sort(tasks.begin(), tasks.end());
  for (int i = 0; i < (int)(M); i++) {
    if (tasks.at(i).first == 1 && tasks.at(i).second == 0) count = -1;
  }
  for (int i = 0; i < (int)(M - 1); i++) {
    if (tasks.at(i).first == tasks.at(i + 1).first &&
        tasks.at(i).second != tasks.at(i + 1).second) {
      count = -1;
    } else {
      A.at(tasks.at(i).first - 1) = tasks.at(i).second;
    }
  }
  A.at(tasks.at(M - 1).first - 1) = tasks.at(M - 1).second;
  if (A.at(0) == 0) {
    A.at(0) = 1;
  }
  for (int i = 0; i < (int)(N); i++) {
    ans += A.at(i) * pow(10, N - i - 1);
  }
  if (count < 0) {
    cout << count << endl;
  } else {
    cout << ans << endl;
  }
}
