#include <bits/stdc++.h>
using namespace std;
void fastIO() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
}
int main() {
  fastIO();
  map<int, int> mp;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (mp.find(s) == mp.end()) {
      mp[s] = c;
    } else if (mp[s] > c) {
      mp[s] = c;
    }
  }
  int ans = 0;
  for (int i = 1; i <= n; i++) {
    ans *= 10;
    ans += mp[i];
  }
  if (to_string(ans).size() == n) {
    cout << ans << '\n';
  } else {
    cout << -1 << '\n';
  }
  return 0;
}
