#include <bits/stdc++.h>
using ll = long long;
using namespace std;
const int INF = 1001001001;
int main(void) {
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  bool f = false;
  for (ll i = (0); i < (m); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    if (mp[a] == 0) mp[a] = b;
    if (mp[a] != b) f = true;
  }
  if (mp[n - 1] == 0) f = true;
  if (f) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (ll i = (0); i < (n); i++) {
    ans += mp[i] * pow(10, n - i - 1);
  }
  cout << ans << endl;
  return 0;
}
