#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  int array[n];
  for (int i = 0; i < n; ++i) array[i] = 0;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (array[a - 1] != 0) {
      if (array[a - 1] != b) {
        cout << -1;
        return 0;
      }
    }
    array[a - 1] = b;
  }
  if (!array[0])
    cout << -1;
  else {
    for (int i = 0; i < n; ++i) cout << array[i];
  }
}
