#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> c(M);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    c[i] = make_pair(a, b);
  }
  vector<int> x(N);
  for (int i = 0; i < (int)(N); i++) {
    x[i] = 10;
  }
  for (int i = 0; i < (int)(M); i++) {
    if (c[i].first - 1 == 0 && c[i].second == 0) {
      continue;
    } else {
      x[c[i].first - 1] = min(c[i].second, x[c[i].first - 1]);
    }
  }
  if (x[0] == 10) {
    cout << -1 << endl;
  } else {
    int sum = 0;
    for (int i = 0; i < (int)(N); i++) {
      if (x[i] != 10) {
        sum += x[i] * pow(10, N - i - 1);
      }
    }
    cout << sum << endl;
  }
}
