#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
int main() {
  int N, M;
  bool can = true;
  cin >> N >> M;
  vector<int> keta(N, -1);
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < M; i++) {
    if (keta.at(s.at(i) - 1) != -1 && c.at(i) != keta.at(s.at(i) - 1)) {
      can = false;
      break;
    }
    if (s.at(i) == 1 && c.at(i) == 0 && N != 1) {
      can = false;
      break;
    }
    keta.at(s.at(i) - 1) = c.at(i);
  }
  if (can) {
    for (int i = 0; i < N; i++) {
      if (i == 0) {
        cout << max(1, keta.at(i));
      } else
        cout << max(0, keta.at(i));
    }
  } else
    cout << -1;
  cout << endl;
}
