#include <bits/stdc++.h>
using namespace std;
int main(int argc, const char* argv[]) {
  int N, M;
  cin >> N >> M;
  vector<int> checked(N, 0);
  string num = "";
  for (int i = 0; i < N; i++) num += "0";
  for (int i = 0; i < M; i++) {
    int s, c;
    cin >> s >> c;
    if (checked[s - 1] == 1 && num[s - 1] - '0' != c) {
      cout << "-1" << endl;
      return 0;
    }
    checked[s - 1] = 1;
    num[s - 1] = c + '0';
  }
  if (num[0] != '0') {
    cout << num << endl;
    return 0;
  }
  cout << "-1" << endl;
  return 0;
}
