#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N, M;
  cin >> N >> M;
  vector<int> s(M), c(M);
  for (int i = 0; i < (int)M; ++i) cin >> s[i] >> c[i];
  int ans = 0;
  for (int i = 0; i < M; ++i) {
    if (s[i] == 1 && c[i] == 0) {
      cout << -1 << endl;
      goto xyz;
    }
    if (i >= 1)
      for (int j = 0; j < i; ++j) {
        if (s[j] == s[i]) {
          if (c[j] != c[i]) {
            cout << -1 << endl;
            goto xyz;
          } else {
            goto pqr;
          }
        }
      }
    ans += c[i] * round(pow(10, N - s[i]));
  pqr:;
  }
  cout << ans << endl;
xyz:;
}
