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