#include <bits/stdc++.h>
using namespace std;
int compNum(int oldNum, int newNum) {
  if (oldNum == 0) return newNum;
  return min(oldNum, newNum);
}
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> result(N);
  int res = 0;
  vector<int> s(M);
  vector<int> c(M);
  for (int i = 0; i < (M); ++i) {
    cin >> s[i] >> c[i];
    result[s[i] - 1] = compNum(result[s[i] - 1], c[i]);
  }
  if (result.size() > 1 && result[0] == 0) {
    cout << -1 << endl;
    return 0;
  }
  for (int i = 0; i < (N); ++i) {
    res += result[N - i - 1] * pow(10, i);
  }
  cout << res << endl;
}
