#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> S(M), C(M);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    S.at(i) = s;
    C.at(i) = c;
  }
  vector<vector<int>> digit(N);
  for (int i = 0; i < M; i++) {
    digit.at(S.at(i) - 1).push_back(C.at(i));
  }
  bool exceed = false;
  for (int i = 0; i < N; i++) {
    if (digit.at(i).size() > 1) {
      set<int> SET;
      for (int j = 0; j < digit.at(i).size(); j++) {
        SET.insert(digit.at(i).at(j));
      }
      if (SET.size() > 1) {
        exceed = true;
      }
    }
  }
  if (exceed) {
    cout << -1 << endl;
    return 0;
  }
  if (!digit.at(0).empty()) {
    if (digit.at(0).at(0) == 0 && N != 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  vector<int> nums = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (!digit.at(i).empty())
      ans += nums.at(digit.at(i).at(0)) * pow(10, N - i - 1);
  }
  if (to_string(ans).size() == N)
    cout << ans << endl;
  else
    cout << -1 << endl;
}
