#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N, M;
  cin >> N >> M;
  vector<long long> A(M), B(M);
  for (long long i = 0; i < M; i += 1) {
    cin >> A[i] >> B[i];
  }
  bool ans = true;
  for (long long i = 0; i < M - 1; i += 1) {
    for (long long j = i + 1; j < M; j += 1) {
      if (A[i] == A[j]) {
        if (B[i] != B[j]) {
          ans = false;
        } else
          A[i] = 0;
        B[i] = 0;
      }
    }
  }
  if (N > 1) {
    for (long long i = 0; i < M; i += 1) {
      if (A[i] == 1 && B[i] == 0) ans = false;
    }
  }
  if (ans) {
    long long K = 0;
    for (long long i = 0; i < M; i += 1) {
      K += B[i] * pow(10, N - A[i]);
    }
    cout << K << endl;
  } else
    cout << "-1" << endl;
}
