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