#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) {
  if (N != M || N < M) {
    cout << -1 << endl;
    return;
  }
  vector<int> checked(N);
  for (int i = 0; i < N; i++) checked[i] = -1;
  for (int i = 0; i < M; i++) {
    if (checked[s[i] - 1] == -1) {
      checked[s[i] - 1] = c[i];
    } else if (checked[s[i] - 1] != c[i]) {
      cout << -1 << endl;
      return;
    }
  }
  for (int i = 0; i < N; i++) {
    if (checked[i] == -1) checked[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    cout << checked[i];
  }
  cout << endl;
}
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;
}
