#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  string t = "aaa";
  bool flag = true;
  cin >> n >> m;
  for (int i = 0; i < (m); i++) {
    int s;
    char c;
    cin >> s >> c;
    s--;
    if (t[s] == 'a' || t[s] == c) {
      t[s] = c;
    } else {
      flag = false;
    }
  }
  if (n == 3) {
    if (t[0] == '0') flag = false;
    if (t[0] == 'a') t[0] = '1';
    if (t[1] == 'a') t[1] = '0';
    if (t[2] == 'a') t[2] = '0';
  } else if (n == 2) {
    if (t[0] != 'a') flag = false;
    if (t[1] == '0') flag = false;
    if (t[1] == 'a') t[1] = '1';
    if (t[2] == '0') t[2] = '0';
  } else if (n == 3) {
    if (t[0] != 'a') flag = false;
    if (t[1] != 'a') flag = false;
    if (t[2] == 'a') t[2] = '0';
  }
  if (flag)
    cout << t << endl;
  else
    cout << -1 << endl;
  return 0;
}
