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