#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vs = vector<string>;
using vpll = vector<pair<ll, ll>>;
using vtp = vector<tuple<ll, ll, ll>>;
using vb = vector<bool>;
template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vpll ab(m);
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    ll a, b;
    cin >> a >> b;
    a--;
    ab[i] = {a, b};
  }
  vb check(n);
  vll num(n);
  for (long long i = (long long)(0); i < (long long)(m); ++i) {
    ll a, b;
    tie(a, b) = ab[i];
    if (check[a]) {
      if (num[a] != b) {
        cout << -1 << endl;
        return 0;
      }
    } else {
      check[a] = true;
      num[a] = b;
    }
  }
  if (n == 0) {
    cout << num[0] << endl;
  } else {
    if (check[0] && num[0] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (!check[0] && num[0] == 0) {
      num[0] = 1;
    }
    for (long long i = (long long)(0); i < (long long)(n); ++i) {
      cout << num[i];
    }
    cout << endl;
  }
}
