#include <bits/stdc++.h>
using namespace std;
using ll = long long;
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;
}
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }
int main() {
  cin.tie(0);
  ios::sync_with_stdio(0);
  cout << fixed << setprecision(20);
  ll N, M;
  cin >> N >> M;
  vector<ll> ans(N, -1);
  for (ll i = 0; i < (M); ++i) {
    ll s, c;
    cin >> s >> c;
    --s;
    if (ans[s] != -1 and ans[s] != c) cout << (-1) << '\n', exit(0);
    ans[s] = c;
  }
  if (ans[0] == 0) cout << (-1) << '\n', exit(0);
  if (ans[0] == -1) ans[0] = 1;
  string out = "";
  for (auto a : ans) {
    if (a == -1) a = 0;
    out += to_string(a);
  }
  cout << (out) << '\n';
  return 0;
}
