#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, m;
  cin >> n >> m;
  string ans(n, '*');
  set<pair<int, int> > s;
  for (int i = (0); i < int(m); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    s.insert({a, b});
  }
  for (auto p : s) {
    int pos = p.first, val = p.second;
    if (ans[pos] == '*')
      ans[pos] = char('0' + val);
    else {
      cout << -1 << endl;
      return 0;
    }
  }
  for (int i = (0); i < int(n); i++)
    if (ans[i] == '*') ans[i] = '9';
  cout << (ans[0] == '0' ? "-1" : ans) << endl;
}
