#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M;
  cin >> N >> M;
  int a = 10, b = 10, c = 10;
  int ans2 = 1000;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    if (N - x + 1 == 3) {
      if (a == 10)
        a = y;
      else if (a != y) {
        ans2 = -1;
        break;
      }
    }
    if (N - x + 1 == 2) {
      if (b == 10)
        b = y;
      else if (b != y) {
        ans2 = -1;
        break;
      }
    }
    if (N - x + 1 == 1) {
      if (c == 10)
        c = y;
      else if (c != y) {
        ans2 = -1;
        break;
      }
    }
  }
  if (a == 10) a = 0;
  if (b == 10) b = 0;
  if (c == 10) c = 0;
  int ans = a * 100 + b * 10 + c;
  if (ans == 0 && N > 1) ans = -1;
  ans = min(ans, ans2);
  cout << ans << endl;
}
