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