#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  int all[5][2], ans = -1;
  string tran = "000";
  for (int i = 0; i < m; i++) {
    cin >> all[i][0] >> all[i][1];
  }
  for (int i = 0; i < m; i++) {
    if (tran[all[i][0] - 1] == '0' || (all[i][1] + 48) == tran[all[i][0] - 1]) {
      tran[all[i][0] - 1] = all[i][1] + 48;
    } else {
      cout << ans << endl;
      return 0;
    }
  }
  ans = (tran[0] - 48) * 100 + (tran[1] - 48) * 10 + (tran[2] - 48);
  if (n > 1 && ans == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n == 1) ans /= 100;
  if (n == 2) {
    ans /= 10;
    if (ans < 10) ans += 10;
  }
  if (n == 3) {
    if (ans < 100) ans += 100;
  }
  cout << ans << endl;
  return 0;
}
