#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  std::unordered_map<int, int> posValMap;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    auto it = posValMap.find(s);
    if (it != posValMap.end() && it->second != c) {
      cout << -1;
      return 0;
    }
    if (s == 1 && c == 0) {
      cout << -1;
      return 0;
    }
    posValMap[s] = c;
  }
  int ret = 0;
  for (int i = 0; i < N; i++) {
    int tempVal = (i == 0) ? 1 : 0;
    auto it = posValMap.find(i + 1);
    if (it != posValMap.end()) {
      tempVal = it->second;
    }
    ret += tempVal * std::pow(10, N - 1 - i);
  }
  cout << ret;
  return 0;
}
