#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
const int MOD = 1e9 + 7;
const int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};
int main() {
  cin.sync_with_stdio(false);
  cin.tie(nullptr);
  int N, M;
  cin >> N >> M;
  vector<pii> vec(M);
  for (int i = 0; i < M; ++i) cin >> vec[i].first >> vec[i].second;
  for (int i = 1; i <= 999; ++i) {
    string s = to_string(i);
    if ((int)s.size() != N) continue;
    bool flg = 1;
    for (int j = 0; j < M; ++j) {
      if (s[vec[j].first - 1] != vec[j].second + 48) {
        flg = 0;
        break;
      }
    }
    if (flg) return cout << i, 0;
  }
  cout << -1;
  return 0;
}
