#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans = 0;
  bool none = false;
  cin >> N >> M;
  vector<int> s(M), c(M);
  vector<bool> keta(N, false), keta2(N, false);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    if (c.at(i) != 0) {
      keta.at(s.at(i) - 1) = true;
    }
    for (int j = 0; j < i; j++) {
      if (s.at(i) == s.at(j) && c.at(i) != c.at(j)) {
        none = true;
      }
    }
  }
  if (keta.at(0) == false) {
    none = true;
  }
  if (none == true) {
    cout << -1 << endl;
  }
  for (int i = 0; i < M; i++) {
    if (none == false && keta2.at(s.at(i) - 1) == false) {
      ans = ans + c.at(i) * pow(10, N - s.at(i));
      keta2.at(s.at(i) - 1) = true;
    }
  }
  if (none == false) {
    cout << ans << endl;
  }
}
