#include <bits/stdc++.h>
using namespace std;
int main(int argc, char* argv[]) {
  int N, M;
  cin >> N >> M;
  int i;
  string T;
  for (i = 0; i < N; i++) {
    T += " ";
  }
  int s;
  char c;
  for (i = 0; i < M; i++) {
    cin >> s >> c;
    if (T[s - 1] == ' ') {
      T[s - 1] = c;
    } else if (T[s - 1] > c) {
      T[s - 1] = c;
    }
  }
  for (i = 0; i < N; i++) {
    if (T[i] == ' ') {
      T[i] = '0';
    }
  }
  if (T[0] == '0') {
    if (T.size() == 1) {
      cout << T << endl;
      return 0;
    }
    cout << -1 << endl;
    return 0;
  }
  cout << T << endl;
  return 0;
}
