#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  int s, c;
  for (int i = 0; i < (m); ++i) {
    cin >> s >> c;
    if (mp.count(s) == 0) {
      mp[s] = c;
    } else {
      if (mp[s] != c) {
        cout << "-1" << endl;
        return 0;
      }
    }
    if (s == 1 && c == 0) {
      cout << "-1" << endl;
      return 0;
    }
  }
  vector<int> ans(n);
  for (auto i = mp.begin(); i != mp.end(); ++i) {
    ans[i->first - 1] = i->second;
  }
  for (int i = 0; i < (n); ++i) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
