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