#include <bits/stdc++.h>
using namespace std;
int N;
int M;
int s[7];
int c[7];
int ans[4] = {-8192, -1, -1, -1};
int main() {
  cin >> N >> M;
  for (int i = 1; i < M + 1; i++) {
    cin >> s[i] >> c[i];
  }
  for (int i = 1; i < M + 1; i++) {
    if (ans[s[i]] == -1 || ans[s[i]] == c[i]) {
      ans[s[i]] = c[i];
    } else {
      cout << '-1' << endl;
      exit(0);
    }
  }
  if (ans[1] == 0 and ans[2] == -1 and ans[3] == -1) {
    cout << '0' << endl;
  }
  if (N >= 2) {
    if (ans[1] == 0) {
      cout << '-1' << endl;
      exit(0);
    }
  }
  if (N == 1) {
    if (ans[1] == -1) {
      ans[1] = 0;
    }
    cout << ans[1] << endl;
  }
  if (N == 2) {
    if (ans[1] == -1) {
      ans[1] = 1;
    }
    if (ans[2] == -1) {
      ans[2] = 0;
    }
    cout << ans[1] << ans[2] << endl;
  }
  if (N == 3) {
    if (ans[1] == -1) {
      ans[1] = 1;
    }
    if (ans[2] == -1) {
      ans[2] = 0;
    }
    if (ans[3] == -1) {
      ans[3] = 0;
    }
    cout << ans[1] << ans[2] << ans[3] << endl;
  }
}
