#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, int>> sc(N);
  for (int i = 0; i < M; i++) {
    cin >> sc[i].first >> sc[i].second;
  }
  map<int, int> v;
  for (int i = 1; i <= N; i++) {
    v[i] = -1;
  }
  bool flg = true;
  for (int i = 0; i < M; i++) {
    int i_ = sc[i].first;
    if (v[i_] == -1) {
      v[i_] = sc[i].second;
    } else if (v[i_] != sc[i].second) {
      flg = false;
      break;
    }
  }
  if (v[1] == 0) {
    flg = false;
  } else if (v[1] == -1) {
    if (N == 1) {
      v[1] = 0;
    } else {
      v[1] = 1;
    }
  }
  int answer = -1;
  if (flg) {
    answer = 0;
    for (int i = 1; i <= N; i++) {
      if (v[i] != -1) {
        answer += v[i] * pow(10, N - i);
      }
    }
  }
  cout << answer << endl;
  return 0;
}
