#include <bits/stdc++.h>
using namespace std;
int N, M;
int s, c;
int main(void) {
  cin >> N >> M;
  int res[N];
  for (int i = 0; i < (N); i++) res[i] = -1;
  for (int i = 0; i < (M); i++) {
    cin >> s >> c;
    if (res[s - 1] == -1 or res[s - 1] == c) {
      res[s - 1] = c;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (N >= 2 and res[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (N == 1 and res[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  if (res[0] == -1)
    cout << 1;
  else
    cout << res[0];
  for (int t = 1; t < N; t++) {
    if (res[t] == -1)
      cout << 0;
    else
      cout << res[t];
  }
  cout << endl;
  return 0;
}
