#include <bits/stdc++.h>
void solve() {
  int n, m;
  std::cin >> n >> m;
  std::map<int, int> num;
  for (int i = 0; i < 3; i++) num.insert(std::pair<int, int>((i + 1), -1));
  int s[5];
  int c[5];
  for (int i = 0; i < 5; i++) s[i] = c[i] = -1;
  for (int i = 0; i < m; i++) std::cin >> s[i] >> c[i];
  bool ans = true;
  for (int i = 0; i < m; i++) {
    if (num[s[i]] == -1)
      num[s[i]] = c[i];
    else if (num[s[i]] != c[i]) {
      ans = false;
      break;
    }
  }
  int real_num = 0;
  if (ans) {
    for (int i = 0; i < n; i++) {
      if (i == n - 1 && n > 1 && num[n] == -1)
        real_num += std::pow(10, i);
      else
        real_num += ((num[i + 1] == -1 ? 0 : num[i + 1]) * std::pow(10, i));
    }
    std::cout << real_num << std::endl;
  } else {
    std::cout << -1 << std::endl;
  }
}
int main() {
  solve();
  return 0;
}
