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