#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int n, m, cnt = 0, ans = 0;
  cin >> n >> m;
  map<int, int> mp;
  vector<int> vec(n);
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (vec.at(s - 1) != 0 && mp.at(s) != c)
      cnt++;
    else {
      mp[s] = c;
      vec.at(s - 1) += 1;
      ans += (pow(10, n - s)) * c;
    }
  }
  if (cnt != 0)
    cout << -1 << endl;
  else {
    if (n != 1 && ans == 0)
      cout << -1 << endl;
    else
      cout << ans << endl;
  }
}
