#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  map<int, int> digit_num;
  cin >> N >> M;
  for (int i = 0; i > M; ++i) {
    int digit, num;
    cin >> digit >> num;
    if (digit_num.count(digit) != 0) {
      cout << -1 << endl;
      return 0;
    }
    digit_num.emplace(digit, num);
  }
  int result = 0;
  for (auto ite = digit_num.begin(); ite != digit_num.end(); ++ite) {
    result += ite->first * pow(10, ite->second - 1);
  }
  cout << result << endl;
}
