#include <bits/stdc++.h>
using namespace std;
const double EPS = 1e-9;
long long m_pow(long long a, long long n) {
  if (n == 0) return 1;
  if (n % 2 == 0) {
    long long t = m_pow(a, n / 2);
    return t * t % 1000000007;
  }
  return a * m_pow(a, n - 1) % 1000000007;
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  long long n, m;
  cin >> n >> m;
  vector<long long> s(m), c(m);
  for (long long i = (0); i < ((m)); ++i) {
    cin >> s[i] >> c[i];
    s[i]--;
  }
  vector<long long> memo(n, -1);
  if (m == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (long long i = (0); i < ((m)); ++i) {
    if ((memo[s[i]] != -1 && memo[s[i]] != c[i]) || (s[i] == 0 && c[i] == 0)) {
      cout << -1 << endl;
      return 0;
    } else {
      memo[s[i]] = c[i];
    }
  }
  if (memo[0] == -1) memo[0] = 1;
  long long ret = 0;
  for (long long i = ((n)-1); i >= (0); --i) {
    if (memo[i] != -1) ret += memo[i] * pow(10, (n - i));
  }
  cout << ret / 10 << endl;
  return 0;
}
