#include <bits/stdc++.h>
using namespace std;
int ans[10];
int32_t main() {
  int n, m;
  cin >> n >> m;
  unordered_map<int, int> mp;
  for (int i = 1; i <= m; i++) {
    int x, y;
    cin >> x >> y;
    if (x == 1 and y == 0 and n != 1) {
      cout << -1;
      return 0;
    }
    if (mp.find(x) != mp.end()) {
      if (mp[x] != y) {
        cout << "-1";
        return 0;
      }
    }
    mp[x] = y;
  }
  for (auto &i : mp) {
    ans[i.first] = i.second;
  }
  if (n != 1) {
    if (mp.find(1) == mp.end()) {
      ans[0] = 1;
    }
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i];
  }
  return 0;
}
