#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  array<int, 3> S;
  S.fill(-1);
  int s, c;
  for (int i = 0; i < M; i++) {
    cin >> s >> c;
    if (N > 1 && s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (S[s - 1] != -1) {
      if (S[s - 1] != c) {
        cout << -1 << endl;
        return 0;
      }
    }
    S[s - 1] = c;
  }
  for (int i = 0; i < S.size(); i++) {
    if (i == 0) {
      cout << max(S[i], 1);
      continue;
    }
    cout << max(S[i], 0);
  }
  cout << endl;
  return 0;
}
