#include <bits/stdc++.h>
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000009;
void solve() {
  int n;
  int m;
  cin >> n >> m;
  vector<int> s;
  vector<int> c;
  for (long long i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    s.emplace_back(x);
    c.emplace_back(y);
  }
  for (long long i = 0; i < 1000; i++) {
    auto st = to_string(i);
    bool b = true;
    for (long long j = 0; j < m; j++) {
      if (s[j] > st.size()) {
        b = false;
        break;
      }
      if (st[s[j] - 1] != (c[j] + '0')) {
        b = false;
        break;
      }
    }
    if (b) {
      cout << i << endl;
      return;
    }
  }
  cout << -1 << endl;
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  solve();
  return 0;
}
