#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, t, s;
  char c;
  char S[10];
  memset(S, '0', sizeof(S));
  map<int, char> m;
  int flag = 1;
  cin >> n >> t;
  while (t--) {
    cin >> s >> c;
    if (m.count(s - 1) == 0) {
      S[s - 1] = c;
      m[s - 1] = c;
    } else {
      if (m[s - 1] != c) {
        flag = 0;
      }
    }
  }
  if (flag == 0)
    puts("-1");
  else {
    int cnt = 0, k = 0;
    string ans = "";
    for (int i = 0; i < n; i++) {
      if (S[i] == '0')
        cnt++;
      else {
        k = i;
        break;
      }
    }
    for (int i = k; i < n; i++) ans += S[i];
    if (cnt == n || ans.length() != n)
      puts("-1");
    else {
      cout << ans;
    }
  }
  return 0;
}
