#include <bits/stdc++.h>
using namespace std;
int digitplus(int x) {
  int ans = 1;
  while (x > 0) {
    ans *= 10;
    x--;
  }
  return ans;
}
int main() {
  int N, M, digi, ans = 0;
  bool trans = true;
  cin >> N >> M;
  vector<int> s(M), c(M), ansv(N);
  for (int i = 0; i < M; i++) {
    cin >> s.at(i) >> c.at(i);
  }
  for (int i = 0; i < N; i++) ansv.at(i) = -1;
  for (int i = 0; i < M; i++) {
    digi = digitplus((N - s.at(i))) * c.at(i);
    if (ansv.at(N - s.at(i)) == -1 || ansv.at(N - s.at(i)) == digi) {
      if (s.at(i) == 1 && c.at(i) == 0) {
        trans = false;
        break;
      } else {
        ansv.at(N - s.at(i)) = digi;
      }
    } else {
      trans = false;
      break;
    }
  }
  for (int i = 0; i < N; i++) {
    if (ansv.at(i) == -1) ansv.at(i) = 0;
  }
  if (trans) {
    for (int i = 0; i < N; i++) {
      if (i == N - 1 && ansv.at(i) == 0 && i != 0) {
        ans += digitplus(i);
      }
      ans += ansv.at(i);
    }
    cout << ans << endl;
  } else
    cout << -1 << endl;
}
