#include <bits/stdc++.h>
int main() {
  int n, m;
  std::cin >> n >> m;
  std::vector<int> s(m);
  std::vector<char> c(m);
  for (int i = 0; i != m; ++i) {
    std::cin >> s[i] >> c[i];
  }
  std::string ans;
  for (int i = 0; i != n; ++i) {
    ans.push_back('a');
  }
  char cur, nxt;
  for (int i = 0; i != m; ++i) {
    cur = ans[s[i] - 1];
    nxt = c[i];
    if (cur != 'a' && cur != nxt) {
      std::cout << -1 << std::endl;
      return 0;
    }
    ans[s[i] - 1] = c[i];
  }
  if (ans[0] == '0') {
    std::cout << -1 << std::endl;
    return 0;
  }
  for (int i = 1; i != ans.size(); ++i) {
    if (ans[i] == 'a') {
      ans[i] = '0';
    }
  }
  std::cout << ans << std::endl;
  return 0;
}
