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