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