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