#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> ans(N, -1);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
    if (ans.at(s.at(i) - 1) != -1) {
      if (ans.at(s.at(i) - 1) == c.at(i))
        continue;
      else {
        ans.at(N - 1) = -1;
        break;
      }
    } else {
      ans.at(s.at(i) - 1) = c.at(i);
    }
  }
  if (ans.at(N - 1) == -1)
    cout << -1 << endl;
  else {
    int answer = 0;
    for (int i = 0; i < N; i++) {
      if (ans.at(i) == -1) ans.at(i) = 0;
      answer += pow(10, N - 1 - i) * ans.at(i);
    }
    cout << answer << endl;
  }
}
