#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];
    cin >> c[i];
  }
  int ans = 0;
  map<int, int> m;
  for (int i = 0; i < M; ++i) {
    if (m.find(s[i]) == m.end() || m[s[i]] == c[i])
      m.insert(make_pair(s[i], c[i]));
    else {
      ans = -1;
      break;
    }
  }
  if (N > 1 && m[1] == 0) ans = -1;
  if (ans == 0) {
    if (N == 3) ans = m[1] * 100 + m[2] * 10 + m[3];
    if (N == 2) ans = m[1] * 10 + m[2];
    if (N == 1) ans = m[1];
  }
  cout << ans << endl;
}
