#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> numbers(N, 0);
  bool TF = true;
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (s == 1 && c == 0) {
      TF = false;
      break;
    }
    if (numbers[s - 1] == 0) {
      numbers[s - 1] = c;
    } else {
      if (numbers[s - 1] == c) continue;
      TF = false;
      break;
    }
  }
  numbers[0] = max(numbers[0], 1);
  if (TF) {
    for (auto x : numbers) {
      cout << x;
    }
    cout << endl;
  } else {
    cout << "-1" << endl;
  }
  return 0;
}
