#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, a = 0, x;
  cin >> N >> M;
  vector<int> c(M), s(M), used(3, 0);
  for (int i = 0; i < (int)M; i++) {
    cin >> s.at(i) >> c.at(i);
    if (used.at(s.at(i) - 1) = !0 && used.at(s.at(i) - 1) != c.at(i)) {
      cout << -1 << endl;
      return 0;
    }
    if (used.at(s.at(i) - 1) == 0) a += pow(10, s.at(i) - 1) * c.at(i);
    used.at(s.at(i) - 1) = c.at(i);
    if (s.at(i) == 1 && c.at(i) == 0) {
      cout << -1 << endl;
      return 0;
    }
  }
  cout << a << endl;
}
