#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < (M); ++i) {
    int n, m;
    cin >> n >> m;
    s[i] = n, c[i] = m;
  }
  vector<int> digits(N);
  for (int i = 0; i < (M); ++i) {
    digits[s[i] - 1] = c[i];
  }
  if (digits.size() != 1 && digits[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  string ans;
  for (auto d : digits) {
    ans += to_string(d);
  }
  cout << ans << endl;
}
