#include <bits/stdc++.h>
using namespace std;
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
template <typename T>
void coutVector(vector<T> v) {
  for (int i = 0; i < int(v.size()); ++i) {
    if (i > 0)
      cout << " " << v[i];
    else
      cout << v[i];
  }
  cout << endl;
}
template <typename T>
void coutVectorWithEndl(vector<T> v) {
  for (int i = 0; i < int(v.size()); ++i) {
    cout << v[i] << endl;
  }
}
template <typename T>
vector<T> cinVector(int n) {
  vector<T> res(n);
  for (int i = 0; i < n; ++i) {
    cin >> res[i];
  }
  return res;
}
const long long MOD = 1e9 + 7;
int main() {
  int N, M;
  cin >> N >> M;
  vector<pair<int, char>> sc;
  for (int i = (int)(0); i < (int)(M); ++i) {
    int s;
    char c;
    cin >> s >> c;
    sc.push_back(make_pair(s, c));
  }
  int res = 1000;
  for (int i = (int)(1); i < (int)(1000); ++i) {
    string s = to_string(i);
    if ((int)s.size() != N) continue;
    bool ok = true;
    for (int j = (int)(0); j < (int)(M); ++j) {
      ok &= s[sc[j].first - 1] == sc[j].second;
    }
    if (ok) res = min(res, i);
  }
  if (res > 999)
    cout << -1 << endl;
  else
    cout << res << endl;
}
