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