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