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