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