#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18L + 1;
int main() {
  int n, m;
  map<int, int> mp;
  cin >> n >> m;
  for (int i = 0; i < (m); ++i) {
    int s, c;
    cin >> s >> c;
    if (mp.find(s) != mp.end() && mp.find(s)->second != c) {
      cout << -1 << endl;
      return 0;
    } else
      mp[s] = c;
  }
  int ans = 0;
  for (auto it = mp.begin(); it != mp.end(); it++) {
    if (mp.size() == 1 && it->first == 1 && it->second == 0) {
      cout << -1 << endl;
      return 0;
    }
    ans += it->second;
    ans *= pow(10, 3 - it->first);
  }
  cout << ans << endl;
  return 0;
}
