#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> data(N, 10);
  for (int i = 0; i < M; i++) {
    int keta, num;
    cin >> keta >> num;
    keta--;
    data[keta] = min(data[keta], num);
  }
  int ans = 0;
  for (int i = 0; i < N; i++) {
    if (data[i] == 10) {
      data[i] = 0;
    }
    if (i == 0 && data[i] == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans += data[i] * pow(10, N - i - 1);
  }
  cout << ans << endl;
}
