#include <bits/stdc++.h>
using namespace std;
int main(void) {
  long long n, m;
  cin >> n >> m;
  long long check[n];
  for (long long i = 0; i < n; i++) check[i] = 10;
  for (long long i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    check[s - 1] = min(check[s - 1], c);
  }
  for (long long i = 0; i < n; i++) {
    if (check[i] == 10) check[i] = 0;
  }
  bool c = true;
  long long ans = 0;
  if (check[0] == 0 && n != 1) c = false;
  if (c == true) {
    for (long long i = 0; i < n; i++) ans += check[i] * pow(10, n - i - 1);
  } else
    ans = -1;
  cout << ans << endl;
  return 0;
}
