#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> keta(N, -1);
  bool flag = true;
  for (int(i) = 0; (i) < (M); ++(i)) {
    int s, c;
    cin >> s >> c;
    s--;
    if (keta[s] == -1) {
      keta[s] = c;
    } else if (keta[s] != c) {
      flag = false;
    }
  }
  if (N != 1) {
    if (keta[0] == -1) {
      keta[0] = 1;
    } else {
      flag = false;
    }
  }
  if (N == 1 && keta[0] == -1) {
    keta[0] = 0;
  }
  if (flag == false) {
    cout << -1 << endl;
    return 0;
  }
  for (int(i) = 0; (i) < (N); ++(i)) {
    if (keta[i] == -1) {
      keta[i] = 0;
    }
    cout << keta[i];
  }
  cout << endl;
  return 0;
}
