#include <bits/stdc++.h>
using namespace std;
int main() {
  int M;
  int N;
  cin >> N >> M;
  int S[M];
  char C[M];
  for (int i = 0; i < M; i++) {
    cin >> S[i] >> C[i];
  }
  stringstream ss;
  ss << setw(N) << setfill('0') << 0;
  string ans = ss.str();
  if (N == 1 && M == 0)
    cout << 0 << endl;
  else if (M == 0) {
    ans.at(0) = '1';
    cout << ans << endl;
  } else {
    bool can = true;
    for (int i = 0; i < M; i++) {
      if (ans.at(S[i] - 1) == '0') {
        ans.at(S[i] - 1) = C[i];
      } else if (ans.at(S[i] - 1) != C[i]) {
        can = false;
        break;
      }
    }
    if (!can)
      cout << -1 << endl;
    else {
      if (ans.at(0) == '0') {
        ans.at(0) = 1;
        cout << ans << endl;
      } else
        cout << ans << endl;
    }
  }
}
