#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> S(N + 1, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (S[s] != -1 && S[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    S[s] = c;
  }
  if (N > 1 && S[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (i == 1) {
      if (S[i] == -1) {
        cout << 1;
      } else {
        cout << S[i];
      }
    } else {
      if (S[i] == -1) {
        cout << 0;
      } else {
        cout << S[i];
      }
    }
  }
}
