#include <bits/stdc++.h>
const int INFI = (1 << 29);
const long long INFL = (1LL << 62);
using namespace std;
string res = "99999999999999";
long long n, m;
vector<pair<long long, char> > r;
void rec(string s) {
  if (int(s.size()) == n) {
    bool ok = true;
    for (long long i = 0; i < m; i++)
      if (s[r[i].first - 1] != r[i].second) ok = false;
    if (ok) res = min(res, s);
    return;
  }
  if (s == "0") s = "";
  for (char i = '0'; i <= '9'; i++) {
    if (!int(s.size()) && (i == '0')) continue;
    s += i;
    rec(s);
    s.pop_back();
  }
}
void solve() {
  cin >> n >> m;
  r.resize(m);
  for (long long i = 0; i < m; i++) cin >> r[i].first >> r[i].second;
  rec("0");
  if (res == "99999999999999") {
    cout << "-1\n";
    return;
  }
  cout << res << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  solve();
  return 0;
}
