#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
using P = pair<i64, i64>;
i64 po(i64 n) {
  i64 ret = 1;
  for (i64 i = 0LL; i < (n); ++i) ret *= 10;
  return ret;
}
void solve(long long N, long long M, std::vector<long long> s,
           std::vector<long long> c) {
  i64 b = po(N - 1);
  for (i64 i = (b); i < (b * 10); ++i) {
    bool flag = true;
    for (i64 j = 0LL; j < (M); ++j) {
      flag &= (i / po(N - s[j])) % 10 == c[j];
    }
    if (flag) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}
struct IoSetup {
  IoSetup() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    cerr << fixed << setprecision(10);
  }
} iosetup;
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;
}
