#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> d(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (d[s - 1] == c) continue;
    if (d[s - 1] == -1)
      d[s - 1] = c;
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  bool valid = false;
  for (int i = 0; i < N; i++) {
    if (d[i] != -1 && d[i] != 0) valid = true;
    if (!valid) {
      cout << -1 << endl;
      return 0;
    }
  }
  int ret = 0;
  for (int i = 0; i < N; i++) {
    int val = d[i] == -1 ? 0 : d[i];
    ret += val * pow(10, N - i - 1);
  }
  cout << ret << endl;
}
