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