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