#include <bits/stdc++.h>
using namespace std;
unsigned GetDigit(unsigned num) {
  if (num == 0) return 1;
  unsigned digit = 0;
  while (num != 0) {
    num /= 10;
    digit++;
  }
  return digit;
}
int main() {
  int N, M;
  cin >> N >> M;
  if (M == 0) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<int, int>> pairs(M);
  for (int i = 0; i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    pairs.at(i) = make_pair(s, c);
  }
  sort(pairs.begin(), pairs.end());
  if (pairs.at(0).first != 1) {
    cout << -1 << endl;
    return 0;
  }
  vector<pair<int, int>> new_pair;
  new_pair.push_back(make_pair(pairs.at(0).first, pairs.at(0).second));
  for (int i = 1; i < M; i++) {
    if (new_pair.at(new_pair.size() - 1).first == pairs.at(i).first) {
      if (new_pair.at(new_pair.size() - 1).second != pairs.at(i).second) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      new_pair.push_back(make_pair(pairs.at(i).first, pairs.at(i).second));
    }
  }
  int ans = 0;
  for (int i = 0; i < (new_pair.size()); ++i) {
    ans += new_pair.at(i).second * pow(10, N - new_pair.at(i).first);
  }
  if (N != GetDigit(ans)) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
