#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int S[M], C[M];
  for (int i = 0; i < M; ++i) cin >> S[i] >> C[i];
  int bucket[4];
  bucket[0] = -1;
  bucket[1] = -1;
  bucket[2] = -1;
  bucket[3] = -1;
  for (int i = 0; i < M; ++i) {
    if (bucket[S[i]] == -1) {
      bucket[S[i]] = C[i];
    } else {
      if (bucket[S[i]] != C[i]) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  if (N == 3) {
    if (bucket[1] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (bucket[1] != -1) ans += bucket[1] * 100;
    if (bucket[2] != -1) ans += bucket[2] * 10;
    if (bucket[3] != -1) ans += bucket[3] * 1;
    if (ans < 100) {
      ans += 100;
    }
  } else if (N == 2) {
    if (bucket[2] == 0) {
      cout << -1 << endl;
      return 0;
    }
    if (bucket[2] != -1) ans += bucket[2] * 10;
    if (bucket[3] != -1) ans += bucket[3] * 1;
    if (ans < 10) {
      ans += 10;
    }
  } else if (N == 1) {
    ans += bucket[3];
  }
  cout << ans << endl;
  return 0;
}
