#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int a, b;
  int P[M], Q[M];
  int S[N];
  for (int i = 0; i < N; i++) {
    S[i] = 0;
  }
  for (int i = 0; i < M; i++) {
    cin >> a >> b;
    P[i] = a;
    Q[i] = b;
    S[P[i] - 1] = Q[i];
  }
  for (int i = 0; i < M; i++) {
    for (int j = 0; j < M; j++) {
      if (P[i] == P[j] & Q[i] != Q[j]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (N > 1) {
    if (S[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    cout << S[i];
  }
  cout << endl;
}
