#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 < 1000; i++) {
    string str = to_string(i);
    if (N != str.length()) continue;
    for (int j = 0; j < M; j++) {
      int k = s[j] - 1;
      if (str[k] - '0' != c[j])
        break;
      else if (j == M - 1) {
        cout << str << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
