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