#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int S[N];
  S[0] = 1;
  bool S_f[N];
  for (int i = 0; i < N; i++) S[i] = 0;
  if (N > 1) S[0] = 1;
  for (int i = 0; i < M; i++) S_f[i] = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (S_f[s - 1] || c == S[s - 1]) {
      S[s - 1] = c;
      S_f[s - 1] = false;
    } else {
      cout << "-1" << endl;
      return 0;
    }
  }
  if (N > 1 && S[0] == 0) {
    cout << "-1" << endl;
    return 0;
  }
  int tmp = 0;
  for (int i = 0; i < N; i++) {
    tmp += S[i] * pow(10, N - i - 1);
  }
  cout << tmp << endl;
  return 0;
}
