#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m, pos;
  char val;
  cin >> n >> m;
  char a[n];
  for (auto i = 0; i < n; i++) {
    a[i] = '?';
  }
  for (auto i = 0; i < m; i++) {
    cin >> pos >> val;
    if (a[n - pos] == '?') {
      a[n - pos] = val;
    } else {
      if (a[n - pos] == val) {
        continue;
      } else {
        cout << "-1";
        return 0;
      }
    }
  }
  if (a[n - 1] == '0' || a[n - 1] == '?')
    cout << "-1";
  else {
    for (auto i = n - 1; i >= 0; i--) {
      if (a[i] == '?')
        cout << '0';
      else
        cout << a[i];
    }
  }
  return 0;
}
