#include <bits/stdc++.h>
using namespace std;
mt19937 RNG(chrono::steady_clock::now().time_since_epoch().count());
void solve() {
  long long n, m;
  cin >> n >> m;
  map<long long, long long> mp;
  long long vis[10] = {0};
  for (long long i = 0; i < m; i++) {
    long long a, b;
    cin >> a >> b;
    if (vis[a] && mp[a] != b) {
      cout << "-1";
      return;
    }
    mp[a] = b;
    vis[a]++;
  }
  if (mp[1] == 0 && n > 1) {
    cout << -1;
    return;
  }
  for (long long i = 1; i < n + 1; i++) {
    if (!vis[i])
      cout << 0;
    else
      cout << mp[i];
  }
}
signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  for (long long i = 1; i < t + 1; i++) {
    solve();
  }
  cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}
