#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) {
      cout << -1 << endl;
      return 0;
    } else {
      a[s - 1] = c;
    }
  }
  if (a[n - 1] == 0) {
    cout << -1 << endl;
    return 0;
  } else if (a[n - 1] == -1) {
    a[n - 1] = 1;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] != -1) {
      cout << a[i];
    } else {
      cout << 0;
    }
  }
  return 0;
}
