#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int S[6], C[6];
  cin >> N >> M;
  bool ok = true;
  for (int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
    if (S[i] == 1 && C[i] == 0) ok = false;
    for (int j = 0; j < i; j++) {
      if (S[i] == S[j]) {
        if (C[i] != C[j]) ok = false;
      }
    }
  }
  int ans[4];
  for (int i = 0; i < 3; i++) {
    ans[i] = 1;
  }
  if (ok) {
    for (int i = 0; i < N; i++) {
      ans[S[i] - 1] = C[i];
    }
  }
  if (ok) {
    for (int i = 0; i < N; i++) {
      cout << ans[i];
    }
    cout << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}
