#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, q, index, insert;
  cin >> n >> q;
  string s(n, '0');
  while (q--) {
    cin >> index >> insert;
    index--;
    if (s[index] != '0' and s[index] != (insert + '0')) return cout << -1, 0;
    s[index] = (insert + '0');
  }
  if (s[0] == 0 and n != 1) return cout << -1, 0;
  return cout << s, 0;
}
