#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
ll gcd(ll a, ll b) {
  if (a < b) swap(a, b);
  if (b == 0) return a;
  return gcd(b, a % b);
}
ll beki(ll a, ll b) {
  ll tmp = 1;
  for (int i = 0; i < b; i++) tmp *= a;
  return tmp;
}
ll modPow(ll x, ll a) {
  if (a == 1) return x;
  if (a % 2) return (x * modPow(x, a - 1)) % (ll)(1e9 + 7);
  ll t = modPow(x, a / 2);
  return ((t % (ll)(1e9 + 7)) * (t % (ll)(1e9 + 7))) % (ll)(1e9 + 7);
}
ll modInv(ll x) { return modPow(x, (ll)(1e9 + 7) - 2); }
int N, M;
int s[10], c[10];
int ans[10];
int main() {
  cin >> N >> M;
  for (int i = 0; i < M; i++) cin >> s[i] >> c[i];
  for (int i = 0; i < N; i++) ans[i] = -1;
  for (int i = 0; i < M; i++) {
    int tmp = s[i] - 1;
    if (ans[tmp] == -1) {
      ans[tmp] = c[i];
    } else if (ans[tmp] != c[i]) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < N; i++) {
    if (ans[i] == -1 || ans[i] == 0) {
      if (i == 0) {
        cout << -1 << endl;
        return 0;
      }
      ans[i] = 0;
    }
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
