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