#include <bits/stdc++.h>
using namespace std;
int main() {
  size_t N, M;
  cin >> N >> M;
  string S(N, '0');
  if (N > 1) {
    S[0] = 1;
  }
  vector<int> c(N + 1, -1);
  for (size_t i = 0; i < M; i++) {
    size_t si;
    int temp;
    cin >> si >> temp;
    if (c[si] == -1) {
      c[si] = temp;
    } else {
      if (c[si] != temp) {
        cout << -1 << endl;
        return 0;
      } else {
        c[si] = temp;
      }
    }
    string ss = to_string(temp);
    S[si - 1] = ss[0];
  }
  size_t len = S.length();
  if ((S.length() > 1) && (S[0] == '0')) {
    cout << -1 << endl;
    return 0;
  }
  int ans = stoi(S);
  cout << ans << endl;
  bool check = true;
}
