#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int keta[N];
  if (M == 0) {
    if (N == 1) {
      cout << -1 << endl;
      return 0;
    } else {
      cout << 1;
    }
    for (int i = 0; i < N - 1; i++) {
      cout << i;
    }
    cout << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    keta[i] = -1;
  }
  vector<pair<int, int>> sc(M);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    sc.at(i) = make_pair(s, c);
  }
  sort(sc.begin(), sc.end());
  for (int i = 0; i < M; i++) {
    int s = sc.at(i).first;
    int c = sc.at(i).second;
    if (keta[s - 1] != -1 && keta[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    } else {
      keta[s - 1] = c;
    }
  }
  if (keta[0] == 0) {
    if (N == 1) {
      cout << 0 << endl;
    } else {
      cout << -1 << endl;
    }
    return 0;
  } else if (keta[0] == -1) {
    if (N == 1) {
      cout << 0 << endl;
      return 0;
    } else {
      keta[0] = 1;
    }
  }
  cout << keta[0];
  for (int i = 1; i < N; i++) {
    if (keta[i] == -1) {
      keta[i] = 0;
    }
    cout << keta[i];
  }
  cout << endl;
}
