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