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