#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 998244353;
const ll INF = 1e9 + 9;
const double PI = 4.0 * atan(1.0);
ll powmod(ll a, ll b, const ll MOD) {
  ll res = 1;
  a %= MOD;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, m;
  cin >> n >> m;
  vector<int> s(n + 1, 0);
  bool ok = true;
  while (m--) {
    int si, ci;
    cin >> si >> ci;
    if (s[si] != 0 && s[si] != ci) {
      ok = false;
      break;
    }
    s[si] = ci;
  }
  if (!ok || s[1] == 0)
    cout << "-1";
  else {
    for (int i = 1; i <= n; ++i) cout << s[i];
  }
  return 0;
}
