#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vs = vector<string>;
using vvs = vector<vs>;
ll mod = 1000000000 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vi s(M), c(M);
  vi ans(N, 10);
  for (int i = 0; i < M; ++i) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < M; i++) {
    int d = ans.at(s.at(i) - 1);
    if (d != c.at(i) and d != 10) {
      cout << -1 << endl;
      return 0;
    }
    ans.at(s.at(i) - 1) = c.at(i);
  }
  if (ans.at(0) == 0 and N != 1) {
    cout << -1 << endl;
    return 0;
  }
  if (ans.at(0) == 10) {
    ans.at(0) = 1;
  }
  int sum = 0;
  for (int i = 0; i < N; i++) {
    if (ans.at(i) == 10) {
      ans.at(i) = 0;
    }
    sum += ans.at(i) * (int)pow(10, N - i - 1);
  }
  cout << sum << endl;
}
