#include <bits/stdc++.h>
using namespace std;
int mypow(int n) {
  int ret = 1;
  for (int i = 0; i < n; i++) {
    ret *= 10;
  }
  return ret;
}
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> order;
  bool b = false;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    auto ite = order.find(s);
    if (ite != order.cend() && ite->second != c) {
      b = true;
      break;
    } else if (s == 1 && c == 0) {
      continue;
    } else {
      order.insert(pair<int, int>(s, c));
    }
  }
  auto itete = order.find(1);
  if (itete != order.cend() && itete->second == 0) b = true;
  if (b) {
    cout << "-1" << endl;
    return 0;
  }
  int ans = 0;
  auto ite = order.cbegin();
  while (ite != order.cend()) {
    ans += ite->second * mypow(N - ite->first);
    ite++;
  }
  int min = mypow(N - 1);
  if (ans < min) ans += min;
  cout << ans << endl;
  return 0;
}
