#include <bits/stdc++.h>
using llint = long long int;
using namespace std;
int main() {
  int N, M;
  int S[10], C[10];
  cin >> N >> M;
  for (int i = 0; i < (int)M; ++i) cin >> S[i] >> C[i];
  map<int, int> mp;
  bool check = true;
  int ans = 0;
  for (int i = 0; i < (int)M; ++i) {
    for (int j = 0; j < M; j++) {
      if (S[i] == S[j] && C[i] == C[j] && i != j) {
        S[j] = C[j] = 0;
      }
    }
    if (S[i] == 1 && C[i] == 0 && N > 1) {
      check = false;
      break;
    }
    mp[S[i]]++;
    if (mp[S[i]] >= 2 && S[i] != 0) {
      check = false;
      break;
    }
    ans = ans + (C[i] * pow(10, N - S[i]));
  }
  check ? cout << ans << endl : cout << -1 << endl;
  return 0;
}
