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