#include <bits/stdc++.h>
using namespace std;
int main() {
  int N, M, ans, i, N1, N2, N3;
  N1 = N2 = N3 = 0;
  cin >> N >> M;
  int s[M], c[M];
  if (M == 0) {
    switch (N) {
      case 1:
        cout << "0";
        goto end;
      case 2:
        cout << "10";
        goto end;
      case 3:
        cout << "100";
        goto end;
    }
  }
  for (i = 0; i < M; i++) {
    cin >> s[i] >> c[i];
  }
  for (i = 0; i < M; i++) {
    if (s[i] == 1) {
      N1 = c[i];
    } else if (s[i] == 2) {
      N2 = c[i];
    } else if (s[i] == 3) {
      N3 = c[i];
    }
  }
  for (i = 0; i < M; i++) {
    if (s[i] == 1) {
      if (N1 != c[i]) {
        cout << "-1";
        goto end;
      }
    } else if (s[i] == 2) {
      if (N2 != c[i]) {
        cout << "-1";
        goto end;
      }
    } else if (s[i] == 3) {
      if (N3 != c[i]) {
        cout << "-1";
        goto end;
      }
    }
  }
  if (N1 == 0) {
    cout << "-1";
    goto end;
  }
  if (N == 1) {
    ans = N1;
  } else if (N == 2) {
    ans = N1 * 10 + N2;
  } else if (N == 3) {
    ans = N1 * 100 + N2 * 10 + N3;
  }
  cout << ans;
end:;
}
