#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> checked(N, -1);
  int result = 0;
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    int ind = N - s[i];
    if (checked[ind] != -1) {
      if (checked[ind] != c[i]) {
        result = -1;
        break;
      }
    } else {
      if (N > 1 && s[i] == 1 && c[i] == 0) {
        result = -1;
        break;
      }
      checked[ind] = c[i];
      result += pow(10, ind) * c[i];
    }
  }
  if (result != -1 && checked[N - 1] == -1) {
    result += pow(10, N - 1);
  }
  cout << result << endl;
  return 0;
}
