#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int s[m];
  char c[m];
  int i;
  for (i = 0; i < m; i++) {
    cin >> s[i] >> c[i];
  }
  string result = "";
  for (i = 0; i < n; i++) {
    result += 'a';
  }
  for (i = 0; i < m; i++) {
    if (s[i] > n) {
      cout << -1 << endl;
      return 0;
    }
    if (result.at(s[i] - 1) == 'a') {
      result.at(s[i] - 1) = c[i];
    } else if (result.at(s[i] - 1) != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (result.at(0) == '0') {
    cout << -1 << endl;
    return 0;
  }
  for (i = 0; i < n; i++) {
    if (result.at(i) == 'a') {
      result.at(i) = '0';
    }
  }
  cout << result << endl;
  return 0;
}
