#include <bits/stdc++.h>
using namespace std;
const int c_YET = -1;
const int INF = 1e9 + 1;
const long long LLINF = 1e17 + 1;
const int DX[9] = {0, 0, 1, -1, 1, 1, -1, -1, 0};
const int DY[9] = {1, -1, 0, 0, 1, -1, 1, -1, 0};
const long long MOD = 1e9 + 7;
const long long MAX = 1e9;
const double PI = 3.14159265358979323846264338327950288;
int main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(30);
  int N, M;
  cin >> N >> M;
  if (M != 0) {
    vector<int> S(M);
    vector<char> C(M);
    for (int i = 0; i < M; i++) {
      cin >> S[i] >> C[i];
    }
    string ans = "";
    for (int i = 0; i < N; i++) {
      ans += "a";
    }
    for (int i = 0; i < M; i++) {
      ans[S[i] - 1] = C[i];
    }
    for (int i = 0; i < M; i++) {
      for (int j = 0; j < M; j++) {
        if (S[i] == S[j] && C[i] != C[j]) {
          cout << -1;
          return 0;
        }
      }
    }
    for (int i = 0; i < M; i++) {
      if (S[i] > N) {
        cout << -1;
        return 0;
      }
    }
    for (int i = 1; i < N; i++) {
      if (ans[i] == 'a') {
        ans[i] = '0';
      }
    }
    if (ans[0] == 'a') {
      ans[0] = '1';
    }
    if (ans[0] == '0') {
      cout << -1;
      return 0;
    }
    cout << ans;
  } else {
    if (N != 1) {
      cout << int(pow(10, N - 1));
    } else {
      cout << 0;
    }
  }
}
