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