#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m, s, c;
  cin >> n >> m;
  vector<int> A(n, -1);
  for (int i = 0; i < m; i++) {
    cin >> s >> c;
    if (A[s - 1] != -1) {
      if (A[s - 1] == c) {
        A[s - 1] = c;
      } else {
        cout << -1 << endl;
        exit(0);
      }
    } else {
      A[s - 1] = c;
    }
  }
  for (int i = 0; i < n; i++) {
    if (A[0] == -1) {
      A[0] = 1;
    }
    if (A[i] == -1) {
      A[i] = 0;
    }
  }
  if (n != 1) {
    if (A[0] == 0) {
      cout << -1 << endl;
    } else {
      for (int i = 0; i < n; i++) {
        cout << A[i];
        if (i == n - 1) {
          cout << endl;
        }
      }
    }
  } else {
    cout << A[0] << endl;
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
