#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
void solve(ll N, ll M, vector<ll> s, vector<ll> c) {
  vector<int> v(N, -1);
  int ans = 0;
  for (int i = 0; i != M; ++i) {
    if (v[s[i] - 1] != -1 && v[s[i] - 1] != c[i]) {
      ans = -1;
      break;
    }
    v[s[i] - 1] = c[i];
  }
  if (!v[0]) ans = -1;
  if (ans != -1) {
    for (int i = 0; i != N; ++i) {
      if (v[i] == -1) {
        v[i] = i ? 0 : 1;
      }
    }
    ans = accumulate(v.begin(), v.end(), 0,
                     [](int acc, int x) { return acc * 10 + x; });
  }
  cout << ans << endl;
}
int main() {
  ll N;
  cin >> N;
  ll M;
  cin >> M;
  vector<ll> s(M);
  vector<ll> c(M);
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
  }
  solve(N, M, move(s), move(c));
  return 0;
}
