#include <bits/stdc++.h>
using namespace std;
int main(void) {
  int n, m;
  cin >> n >> m;
  map<int, int> map;
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (map.find(s) != map.end() && map[s] != c) {
      cout << -1 << endl;
      return 0;
    }
    map[s] = c;
  }
  for (auto e : map) {
    ans += pow(10, (n - e.first)) * e.second;
  }
  if (n != 1 && ans == 0) {
    cout << -1 << endl;
    return 0;
  }
  if (n > 1 && map[1] == 0) {
    cout << -1 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}
