#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int array1[M];
  char array2[M];
  for (int i = 0; i < M; i++) {
    cin >> array1[i] >> array2[i];
  }
  int ans = 0;
  bool res = 0;
  for (int i = 0; i < pow(10, N); i++) {
    int mk = 0;
    for (int j = 0; j < M; j++) {
      if (to_string(i).size() == N)
        if (((to_string(i).at(array1[j] - 1) == array2[j]))) mk++;
    }
    if (mk == M) {
      ans = i;
      res = 1;
      break;
    }
  }
  if (M == 0) {
    if (N == 1) {
      ans = 0;
      return 0;
    } else
      ans = pow(10, N - 1);
  }
  if (ans || res)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
