#include <bits/stdc++.h>
using namespace std;
constexpr int64_t MOD = 1e9 + 7;
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);
  int32_t N, M;
  cin >> N >> M;
  vector<int> checked(N, -1);
  for (int i = 0; i < M; i++) {
    int32_t s, c;
    cin >> s >> c;
    if (checked[s - 1] != -1 && checked[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    } else if (N >= 2 && s - 1 == 0 && c == 0) {
      cout << -1 << endl;
      return 0;
    }
    checked[s - 1] = c;
  }
  int32_t res = 0;
  for (int i = 0; i < N; i++) {
    if (i == 0 && checked[i] == -1) {
      res = 1;
    } else if (i == 0) {
      res = checked[i];
    } else if (checked[i] == -1) {
      res = res * 10;
    } else {
      res = res * 10 + checked[i];
    }
  }
  cout << res << endl;
  return 0;
}
