#include <bits/stdc++.h>
using ll = long long;
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> input{};
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if ((N > 1 && s == 1 && c == 0) || s > N) {
      cout << "-1";
      return 0;
    } else if (input.count(s) > 0 && input[s] != c) {
      cout << "-1";
      return 0;
    } else {
      if (input.count(s) == 0) input.insert(make_pair(s, c));
    }
  }
  int ans = 0;
  for (auto itr = input.begin(); itr != input.end(); itr++) {
    ans += pow(10, (N - itr->first)) * itr->second;
  }
  cout << ans;
  return 0;
}
