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