#include <bits/stdc++.h>
using namespace std;
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  vector<set<int> > A;
  vector<set<int> > B;
  for (int i = 0; i < N; ++i) {
    int pos = 0;
    if (i == 0)
      pos = 1;
    else
      pos = 0;
    set<int> temp_a;
    for (int j = pos; j < 10; ++j) {
      temp_a.insert(j);
    }
    A.push_back(temp_a);
    set<int> temp_b;
    for (int j = 0; j < M; ++j) {
      if (i == s[j] - 1) temp_b.insert(c[j]);
    }
    B.push_back(temp_b);
  }
  vector<set<int> > C;
  for (int i = 0; i < N; ++i) {
    set<int> temp_c;
    set_intersection(A[i].begin(), A[i].end(), B[i].begin(), B[i].end(),
                     inserter(temp_c, temp_c.end()));
    C.push_back(temp_c);
  }
  if (C[0].size() == 0)
    cout << -1 << endl;
  else {
    for (int i = 0; i < N; ++i) {
      if (C[i].size() >= 0) cout << *max_element(C[i].begin(), C[i].end());
    }
    cout << endl;
  }
  return;
}
int main() {
  long long N;
  scanf("%lld", &N);
  long long M;
  scanf("%lld", &M);
  std::vector<long long> s(M);
  std::vector<long long> c(M);
  for (int i = 0; i < M; i++) {
    scanf("%lld", &s[i]);
    scanf("%lld", &c[i]);
  }
  solve(N, M, std::move(s), std::move(c));
  return 0;
}
