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