#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  if (M == 0) {
    if (N == 3) {
      cout << "100" << endl;
      return 0;
    }
    if (N == 2) {
      cout << "10" << endl;
      return 0;
    }
    if (N == 1) {
      cout << "0" << endl;
      return 0;
    }
  }
  vector<int> num(N, -1);
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (num[s - 1] == -1) {
      num[s - 1] = c;
    } else if (num[s - 1] != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = 0; i < pow(10, N); i++) {
    int c = 0;
    int tmp = i;
    bool f = true;
    while (c != N) {
      if (tmp % 10 == num[N - c - 1] || num[N - c - 1] == -1) {
        tmp /= 10;
        c++;
        continue;
      }
      f = false;
      break;
    }
    if (f) {
      cout << i << endl;
      return 0;
    }
  }
  cout << "-1" << endl;
  return 0;
}
