#include <map>
#include <utility>
#include <iostream>

#define rep(i,n) for (int i = 0; i < n; i++)

void solve() {
  int n, m;
  std::cin >> n >> m;
  std::map<int, int> num;
  rep(i,3) num.insert(std::pair<int, int>((i+1), -1));
  int s[5];
  int c[5];
  rep(i,5) s[i] = c[i] = -1;
  rep(i,m) std::cin >> s[i] >> c[i];
  bool ans = true;
  rep(i,m) {
    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) {
    rep(i,n) {
      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;
}