#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, 1e9);
  int s, c;
  bool flag = true;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    if (s == 1 && c != 0) ans[s - 1] = min(ans[s - 1], c);
  }
  int answer = 0;
  reverse(begin(ans), end(ans));
  for (int i = 0; i < (int)(n); i++) {
    if (ans[i] == 1e9) ans[i] = 0;
    answer += pow(10, i) * ans[i];
  }
  int len = to_string(answer).length();
  if (len == n) {
    cout << answer << endl;
  } else {
    cout << -1 << endl;
  }
}
