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