#include <bits/stdc++.h>
using namespace std;
long long N, M, H, W, K, Q, A, B;
string S, T;
const long long MOD = (1e+9) + 7;
const long long INF = 1LL << 60;
int main() {
  cin >> N >> M;
  vector<long long> c(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> A >> B;
    --A;
    if ((c[A] != B && c[A] != -1) || (B == 0 && A == 0)) {
      cout << -1 << endl;
      return 0;
    }
    c[A] = B;
  }
  for (int i = 0; i < N; i++) {
    if (c[i] == -1) c[i] = (i == 0 && N != 1);
    cout << c[i];
  }
  cout << endl;
}
