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