#include <bits/stdc++.h>
const int INF = 1 << 29;
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> ans(N, -1);
  for (int64_t i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (ans.at(s - 1) != -1) {
      if (ans.at(s - 1) != c) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      ans.at(s - 1) = c;
    }
  }
  int sum = 0;
  for (int64_t i = 0; i < N; i++) {
    if (ans.at(i) == -1) {
      if (i == 0) {
        ans.at(i) = 1;
      } else {
        ans.at(i) = 0;
      }
    }
    sum += pow(10, N - i - 1) * ans.at(i);
  }
  if (to_string(sum).size() != N)
    cout << -1 << endl;
  else
    cout << sum << endl;
}
