#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));
  if (M == 0) {
    cout << 0 << endl;
    return 0;
  }
  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 (N == 1) {
    cout << ans[0] << endl;
    return 0;
  }
  if (N == 2) {
    if (ans[1] != 0) {
      cout << ans[1];
    } else {
      if (z[1]) {
        cout << -1 << endl;
        return 0;
      }
    }
    cout << ans[0] << endl;
    return 0;
  }
  if (ans[2] != 0) {
    cout << ans[2] << ans[1] << ans[0] << endl;
    return 0;
  } else {
    if (z[2]) {
      cout << -1 << endl;
      return 0;
    } else {
      cout << 1 << ans[1] << ans[0] << endl;
    }
  }
  return 0;
}
