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