#include <bits/stdc++.h>
using namespace std;
int const INF = 1001001001;
int main() {
  int N, M;
  cin >> N >> M;
  int s[M], c[M];
  for (int i = 0; i <= M - 1; ++i) cin >> s[i] >> c[i];
  int ans = INF;
  for (int i = pow(10, N - 1); i <= pow(10, N) - 1; ++i) {
    string S = to_string(i);
    bool ok = true;
    for (int j = 0; j <= M - 1; ++j) {
      if (S.at(s[j] - 1) != c[j] + '0') ok = false;
    }
    if (ok) ans = min(ans, i);
  }
  if (ans != INF)
    cout << ans << endl;
  else
    cout << -1 << endl;
  return 0;
}
