#include <bits/stdc++.h>
using namespace std;
int main() {
  int v[3] = {-1, -1, -1};
  int N, M;
  cin >> N >> M;
  N--;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (v[s] != -1 && v[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    v[s] = c;
  }
  if (N == 0 && v[0] == -1) {
    cout << 0 << endl;
    return 0;
  }
  int i = 0;
  for (; i <= N; i++) {
    if (v[i] != -1) break;
    v[i] = 1;
  }
  for (; i <= N; i++) {
    if (v[i] == -1) v[i] = 0;
  }
  if (v[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  int a = 0;
  int m = 1;
  for (int i = 0; i <= N; i++) {
    a += v[N - i] * m;
    m *= 10;
  }
  cout << a << endl;
  return 0;
}
