#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  int limit;
  int start;
  bool flag = false;
  cin >> N;
  cin >> M;
  int S[M];
  char C[M];
  for (int i = 0; i < M; i++) {
    cin >> S[i];
    cin >> C[i];
  }
  if (N == 1) {
    start = 0;
    limit = 10;
  } else if (N == 2) {
    start = 10;
    limit = 100;
  } else {
    start = 100;
    limit = 1000;
  }
  for (int i = start; i < limit; i++) {
    string i_str;
    i_str = to_string(i);
    for (int j = 0; j < M; j++) {
      if (i_str[(S[j] - 1)] != C[j]) {
        break;
      }
      if (j == M - 1) {
        cout << i;
        exit(0);
      }
    }
  }
  cout << "-1";
}
