#include <bits/stdc++.h>
using namespace std;
long long powM(long long a, long long b, long long m) {
  a %= m;
  long long ans = 1;
  while (b > 0) {
    if (b & 1) ans = ans * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return ans;
}
long long c(long long a, long long b) {
  if (a == 0) return b == 0 ? 1 : 0;
  if (b > a) return 0;
  long long val = 1;
  long long fac = 1;
  for (int i = 1; i <= b; i++) fac *= i;
  for (int i = a; i >= a - b + 1; i--) val *= i;
  return val / fac;
}
long long f(long long n) {
  long long ans = 1LL;
  while (ans <= n) ans <<= 1;
  return ans;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long n, m;
  cin >> n >> m;
  vector<long long> ans(11, 0);
  while (m--) {
    long long a, b;
    cin >> a >> b;
    if (!ans[a] || ans[a] == b)
      ans[a] = b;
    else {
      cout << -1 << "\n";
      return 0;
    }
  }
  if (ans[1] == 0 && n > 1) {
    cout << -1 << "\n";
    return 0;
  }
  long long fin = 100 * ans[1] + 10 * ans[2] + ans[3];
  cout << fin << "\n";
  return 0;
}
