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