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