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