#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;
  }
  bool can = false;
  for (int i = N - 1; i > 0; i--) {
    if (!can && z[i] && ans[i] == 0) {
      cout << -1 << endl;
    }
    if (can && z[i] && ans[i] == 0) {
      ans[i + 1] = 1;
    }
    can = true;
  }
  bool out = false;
  for (int i = N - 1; i >= 0; i--) {
    if (!out && !z[i] && ans[i] == 0) {
      continue;
    }
    cout << ans[i];
    out = true;
  }
  cout << endl;
  return 0;
}
