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