#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
void Main() {
  ll N, M;
  cin >> N >> M;
  vector<ll> info(M, -1);
  for (ll i = 0; i < (ll)(M); i++) {
    ll s, c;
    cin >> s >> c;
    s--;
    if (info[s] != -1 && info[s] != c) {
      cout << -1 << '\n';
      return;
    }
    info[s] = c;
  }
  ll base = 1;
  for (ll i = 0; i < (ll)(N - 1); i++) {
    base *= 10;
  }
  ll ne = base * 10;
  if (N == 1) {
    if (M == 0) {
      cout << 0 << '\n';
      return;
    } else {
      cout << info[0] << '\n';
      return;
    }
  }
  vector<ll> ans;
  for (ll i = base; i < (ll)(ne); i++) {
    string s = to_string(i);
    bool ok = true;
    for (ll j = 0; j < (ll)(M); j++) {
      ll b = info[j];
      if (b == -1) continue;
      if (b != (s[j] - '0')) ok = false;
    }
    if (ok) {
      ans.push_back(i);
    }
  }
  if (ans.size() == 0) {
    cout << -1 << '\n';
  } else {
    sort(ans.begin(), ans.end());
    cout << ans[0] << '\n';
  }
}
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  Main();
  return 0;
}
