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