#include <bits/stdc++.h>
const int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  vector<P> data(m, P(m, 0));
  for (int i = 0; i < (m); ++i) cin >> data.at(i).first >> data.at(i).second;
  int ans = 0;
  while (ans < 1000) {
    ans++;
    string s = to_string(ans);
    if (n != s.length())
      continue;
    else {
      bool can = true;
      for (int i = 0; i < (m); ++i) {
        if (data.at(i).second != s.at(data.at(i).first - 1) - '0') {
          can = false;
          break;
        }
      }
      if (can) {
        cout << ans << endl;
        return 0;
      }
    }
  }
  cout << -1 << endl;
  return 0;
}
