#include <bits/stdc++.h>
using namespace std;
bool check(vector<vector<int>> vec, int M) {
  for (int i = 0; i < M; i++) {
    if (vec.at(i).at(0) == 1 && vec.at(i).at(1) == 0) {
      return true;
    }
  }
  for (int i = 0; i < M - 1; i++) {
    for (int j = i + 1; j < M; j++) {
      if (vec.at(i).at(0) == vec.at(j).at(0)) {
        if (vec.at(i).at(1) != vec.at(j).at(1)) return true;
      }
    }
  }
  return false;
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<vector<int>> vec;
  for (int i = 0; i < M; i++) {
    vector<int> subvec;
    int s, c;
    cin >> s >> c;
    subvec.push_back(s);
    subvec.push_back(c);
    vec.push_back(subvec);
  }
  if (check(vec, M)) {
    cout << -1;
    return 0;
  }
  vector<int> ans(N + 1, 0);
  for (int i = 0; i < M; i++) {
    ans.at(vec.at(i).at(0)) = vec.at(i).at(1);
  }
  int answer = 0;
  answer += ans.at(1) * 100 + ans.at(2) * 10 + ans.at(3);
  cout << answer;
}
