#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  pair<int, int> a[n + 1];
  int b[n + 1];
  for (int i = 1; i <= n; i++) {
    b[i] = 0;
  }
  for (int i = 1; i <= m; i++) {
    cin >> a[i].first >> a[i].second;
    b[a[i].first] = max(b[a[i].first], a[i].second);
  }
  if (b[1] == 0) {
    cout << -1;
    return 0;
  }
  int j = 0;
  for (int i = 1; i <= n; i++) {
    if (b[i] == 0) j++;
  }
  if (j > 1) {
    cout << -1;
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    cout << b[i];
  }
}
