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