#include <bits/stdc++.h>
using namespace std;
typedef vector<pair<long long int, long long int>> vec_p;
const long long int MOD = pow(10, 9) + 7;
const long long int LLINF = pow(2, 61) - 1;
const int INF = pow(2, 30) - 1;
long long int gcd(long long int a, long long int b) {
  return b ? gcd(b, a % b) : a;
}
long long int beki(long long int A, long long int B) {
  long long int C = 1;
  if (B == 0) {
    return 1;
  } else {
    for (long long int i = 0; i < B; i++) {
      C *= A;
    }
    return C;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long int N, M;
  string S;
  cin >> N >> M;
  if (M == 0) {
    cout << beki(10, N - 1) << endl;
  } else {
    vector<long long int> s(M);
    vector<char> c(M);
    for (long long int i = 0; i < (long long int)(M); i++) {
      cin >> s.at(i) >> c.at(i);
    }
    int flag1 = 0;
    for (long long int i = beki(10, N - 1); i < beki(10, N); i++) {
      string tmp;
      bool flag = true;
      tmp = to_string(i);
      for (long long int j = 0; j < (long long int)(M); j++) {
        if (tmp.at(s.at(j) - 1) == c.at(j)) {
        } else {
          flag = false;
        }
      }
      if (flag) {
        cout << i << endl;
        flag1 = 1;
        break;
      }
    }
    if (flag1 == 0) {
      cout << -1 << endl;
    }
  }
}
