#include <bits/stdc++.h>
using namespace std;
int main() {
  long long N;
  cin >> N;
  long long M;
  cin >> M;
  vector<long long> data(N, -1);
  for (long long(i) = long long(0); (i) < long long(M); (i)++) {
    long long a, b;
    cin >> a >> b;
    a--;
    if (data[a] == -1) {
      data[a] = b;
    } else {
      if (data[a] != b) {
        cout << (-1) << endl;
        return 0;
      }
    }
  }
  if (data[0] == 0) {
    if (N == 1) {
      cout << (0) << endl;
      return 0;
    } else {
      cout << (-1) << endl;
      return 0;
    }
  } else {
    if (data[0] == -1) {
      cout << 1;
    } else {
      cout << data[0];
    }
  }
  for (long long(i) = long long(1); (i) < long long(N); (i)++) {
    if (data[i] == -1) {
      cout << 0;
    } else {
      cout << data[i];
    }
  }
  return 0;
}
