#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];
  bool flag[n];
  for (int i = 0; i < n; ++i) flag[i] = 0;
  for (int i = 0; i < n; ++i) array[i] = -1;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    if (array[a - 1] != -1 || flag[a - 1]) {
      if (array[a - 1] != b) {
        cout << -1;
        return 0;
      }
    }
    array[a - 1] = b;
    if (b == 0) flag[a - 1] = 1;
  }
  if (!array[0] && n > 1)
    cout << -1;
  else {
    for (int i = 0; i < n; ++i) cout << (array[i] != -1 ? array[i] : 0);
  }
}
