#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e15;
int main() {
  long long n, m;
  cin >> n >> m;
  map<long long, long long> mp;
  set<long long> st;
  for (int i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    if (st.count(s) && mp[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    mp[s] = c;
    st.insert(s);
  }
  if (mp[n] == 0) {
    cout << -1 << endl;
    return 0;
  }
  string ans = "";
  for (int i = 0; i < n; i++) {
    long long t = mp[i + 1];
    ans += '0' + t;
  }
  cout << ans << endl;
  return 0;
}
