#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int digit[n];
  for (int i = 0; i < n; i++) {
    digit[i] = 999;
  }
  for (int i = 0; i < m; i++) {
    int si, ci;
    cin >> si >> ci;
    if (digit[0] != 0 && si == 1 && ci == 0) continue;
    if (digit[si - 1] > ci) digit[si - 1] = ci;
  }
  if ((digit[0] == 999 && n != 1) || (digit[0] == 0 && n != 1))
    cout << -1 << endl;
  else {
    int ans = 0;
    for (int i = 0; i < n; i++) {
      if (digit[i] == 999) digit[i] = 0;
      ans += digit[i] * pow(10, n - i - 1);
    }
    cout << ans << endl;
  }
  return 0;
}
