#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, n;
  char m;
  cin >> N >> M;
  char num[N];
  vector<int> check(N, 0);
  for (int i = 0; i < N; i++) {
    num[i] = '0';
  }
  for (int i = 0; i < M; i++) {
    cin >> n >> m;
    n--;
    if (check.at(n) == 0) {
      num[n] = m;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  if (num[0] == '0') {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < N; i++) {
    cout << num[i];
  }
  cout << endl;
  return 0;
}
