#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  int num[3] = {0, 0, 0};
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < M; i++) {
    if (s.at(i) == 1 && c.at(i) == 0) {
      cout << -1;
      return 0;
    }
    size_t n_count = std::count(s.begin(), s.end(), s.at(i));
    if ((int)n_count > 1) {
      int temp = s.at(i);
      for (int j = i; j < M; j++) {
        if (s.at(j) == s.at(i))
          if (c.at(j) != c.at(i)) {
            cout << -1;
            return 0;
          }
      }
    }
    num[s.at(i) - 1] = c.at(i);
  }
  int result = num[0] + num[1] * 10 + num[2] * 100;
  cout << result;
}
