#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, m, mxs = 0;
  cin >> n >> m;
  vector<ll> s(m);
  vector<char> c(m);
  rep(i, m) cin >> s[i] >> c[i], s[i]--;

  rep(i, 1000) {
    string S = to_string(i);
    if (S.size() != n) continue;
    bool ok = true;
    rep(j, m) if (S[s[j]] != c[j]) ok = false;
    if (ok) {
      cout << i << endl;
      return 0;
    }
  }

  puts("-1");
  return 0;
}