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