#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
int main() {
  ll n, m;
  cin >> n >> m;
  ll s[m], c[m];
  ll ans = -1;
  for (ll i = 0; i < m; i++) cin >> s[i] >> c[i];
  if (m == 0) {
    if (n == 1) {
      cout << "0" << endl;
      return 0;
    } else {
      cout << pow(10, n - 1) << endl;
      return 0;
    }
  }
  for (ll i = 0; i < m; i++) {
    if (s[i] == 1 && c[i] == 0) {
      if (n == 1) {
        cout << "0" << endl;
        return 0;
      } else {
        cout << "-1" << endl;
        return 0;
      }
    }
  }
  for (ll i = pow(10, n - 1); i < pow(10, n); i++) {
    string st = to_string(i);
    for (ll j = 0; j < st.size(); j++) {
      if (st[s[j] - 1] != c[j]) break;
      if (j == m - 1) ans = i;
    }
    if (ans != -1) break;
  }
  cout << ans << endl;
}
