#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int N, M;
  cin >> N >> M;
  int ans[N];
  memset(ans, 0, sizeof(ans));
  bool z[N];
  memset(z, false, sizeof(z));
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (z[N - s] && ans[N - s] != c) {
      cout << -1 << endl;
      return 0;
    }
    ans[N - s] = c;
    z[N - s] = true;
  }
  if (z && ans[N - 1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = N; i > 0; i--) {
    if (i == N && ans[i - 1] == 0 && N != 1) {
      cout << 1;
      continue;
    }
    cout << ans[i - 1];
  }
  cout << endl;
  return 0;
}
