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