#include <bits/stdc++.h>
using namespace std;
void _main();
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  _main();
}
const int inf = INT_MAX / 2;
const long long infl = 1LL << 60;
template <class T>
bool chmax(T& a, const T& b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int N, M, S[5], C[5];
void _main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) cin >> S[i] >> C[i], S[i]--;
  for (int ans = 0; ans < 1000; ans++) {
    string s = to_string(ans);
    if (s.length() != N) continue;
    bool ok = true;
    for (int i = 0; i < M; i++)
      for (int j = 0; j < N; j++)
        if (j == S[i] && s[j] - '0' != S[i]) ok = false;
    if (ok) {
      cout << ans << endl;
      return;
    }
  }
  cout << -1 << endl;
}
