#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M), ans(5, -1);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 0; i < M; i++) {
    if (ans[s[i] - 1] != -1 && ans[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      exit(0);
    }
    ans[s[i] - 1] = c[i];
  }
  for (int i = 1; i < N; i++) {
    if (ans[0] == -1) {
      ans[0] = 1;
    }
    if (ans[i] == -1) {
      ans[i] = 0;
    }
  }
  if (ans[0] == 0 && N != 1) {
    cout << -1 << endl;
    exit(0);
  }
  if (M == 0) {
    cout << 0 << endl;
    exit(0);
  }
  for (int i = 0; i < N; i++) {
    cout << ans[i];
  }
}
