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