#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long N, M;
  cin >> N >> M;
  vector<long long> s(M);
  vector<long long> c(M);
  map<long long, long long> mm;
  long long result = 0;
  for (long long i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    if (c.at(i) == 0 && s.at(i) == 1 && N != 1) {
      cout << "-1" << endl;
      return;
    }
    if (mm[s.at(i)] != (long long)NULL) {
      if (mm[s.at(i)] != c.at(i)) {
        cout << "-1" << endl;
        return;
      }
      continue;
    }
    mm[s.at(i)] = c.at(i);
    result += pow((long long)10, (N - s.at(i))) * c.at(i);
  }
  if (result != 0 && result < pow((long long)10, N - 1)) {
    cout << "-1" << endl;
    return;
  }
  cout << result << endl;
  return;
}
int main() {
  solve();
  return 0;
}
