#include <bits/stdc++.h>
using namespace std;
int mod = 1000000007;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a * b / gcd(a, b); }
long long int bpow(long long int a, long long int b) {
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = ((res % mod) * (a % mod)) % mod;
    a = ((a % mod) * (a % mod)) % mod;
    b >>= 1;
  }
  return res;
}
long long int fact(long long int n) {
  if ((n == 0) || (n == 1))
    return 1;
  else
    return n * fact(n - 1);
}
void go() {}
int dx[4] = {0, -1, 1, 0};
int dy[4] = {1, 0, 0, -1};
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  std::cout.tie(NULL);
  go();
  int n, m;
  cin >> n >> m;
  int ans = 0;
  map<int, int> mp;
  int arr[4] = {0};
  while (m--) {
    int a, b;
    cin >> a >> b;
    auto it = mp.find(a);
    if (it != mp.end()) {
      if (mp[a] != b) {
        cout << "-1"
             << "\n";
        return 0;
      }
    } else {
      mp[a] = b;
      arr[a] = b;
    }
  }
  for (int i = n; i >= 0; i--) {
    auto it = mp.find(i);
    if (it == mp.end()) {
      cout << "-1"
           << "\n";
      return 0;
    } else
      break;
  }
  int j = 0;
  for (int i = 1; i <= 3; i++) {
    ans = (ans * 10 + arr[i]);
    j++;
  }
  cout << ans << "\n";
}
