#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  vector<int> ans(N);
  for (int i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans[s[i] - 1] = c[i];
  }
  for (int i = 1; i < M; i++) {
    for (int k = 0; k < i; k++) {
      if (s[i] == s[k] && c[i] != c[k]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  if (ans[0] == 0) ans[0] = 1;
  int A;
  for (int i = 0; i < N; i++) {
    A += ans[i] * pow(10, (N - i - 1));
  }
  cout << A << endl;
  return 0;
}
