#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  vector<int> h(N + 1);
  int flag = 0;
  for (int i = 0; i < M; i++) {
    cin >> s[i];
    cin >> c[i];
    if (h[s[i]] == 0 || h[s[i]] == c[i]) {
      h[s[i]] = c[i];
    } else {
      flag = 1;
    }
  }
  if (flag == 1) {
    cout << -1 << endl;
  } else {
    int j = 1;
    while (j <= N) {
      while (h[j] == 0 && j <= N) {
        if (j == N) {
          cout << -1 << endl;
          j++;
          break;
        }
        j++;
      }
      while (j <= N) {
        cout << h[j];
        j++;
      }
    }
  }
  cout << endl;
  return 0;
}
