#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> count(N + 1, 0);
  vector<bool> visit(N + 1, false);
  int s, c;
  for (int i = int(0); i < int(M); ++i) {
    cin >> s >> c;
    if (visit.at(s) && count.at(s) == c) {
      continue;
    }
    if (!visit.at(s)) {
      count.at(s) = c;
      visit.at(s) = true;
    } else {
      cout << -1 << endl;
      return 0;
    }
  }
  int ans = 0;
  bool found_non_zero = false;
  for (int i = int(1); i < int(N + 1); ++i) {
    ans *= 10;
    if (!found_non_zero && count.at(i) == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans += count.at(i);
    found_non_zero = true;
  }
  cout << ans << endl;
  return 0;
}
