#include <bits/stdc++.h>
using namespace std;
int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> num(N, -1);
  if (M == 0) {
    cout << 0 << endl;
    return 0;
  }
  for (size_t i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if ((N != 1 && s == 1 && c == 0) || (c != num[s - 1] && num[s - 1] != -1)) {
      cout << -1 << endl;
      return 0;
    }
    num[s - 1] = c;
  }
  for (size_t i = 0; i < N; i++) {
    if (i == 0 && num[i] == -1) {
      cout << 1;
    } else if (num[i] == -1) {
      cout << 0;
    } else {
      cout << num[i];
    }
  }
  cout << endl;
}
