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