#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<int> ans(N, -1);
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j < M; j++) {
      if (s[j] == 1 && c[j] == 0) {
        cout << -1 << endl;
        return;
      }
      if (s[j] == i) {
        if (ans[N - i] == -1) {
          ans[N - i] = c[j];
        } else if (ans[N - i] != c[j]) {
          cout << -1 << endl;
          return;
        }
      }
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1) {
      ans[i] = 0;
    }
  }
  int out = 0;
  for (int i = 0; i < N; i++) {
    cerr << ans[N - i - 1] << endl;
    out += ans[N - i - 1] * pow(10, N - i - 1);
  }
  cout << out << 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;
}
