#include <bits/stdc++.h>
using ll = long long;
using ld = long double;
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n, m;
  cin >> n >> m;
  vector<ll> vec(n, -1);
  for (int i = 0; i < (int)(m); i++) {
    ll s, y;
    cin >> s >> y;
    s--;
    if (vec[s] != -1 && vec[s] != y) {
      cout << -1 << endl;
      return 0;
    }
    if (s == 0 && y == 0) {
      cout << -1 << endl;
      return 0;
    }
    vec[s] = y;
  }
  for (int i = 0; i < (int)(n); i++) {
    if (i == 0) {
      if (vec[i] == -1) {
        vec[i] = 1;
      }
    }
  }
  ll sum = 0;
  for (int i = 0; i < (int)(n); i++) {
    if (vec[i] >= 1) {
      sum += vec[i] * pow(10, n - i - 1);
    }
  }
  cout << sum << endl;
  return 0;
}
