#include <bits/stdc++.h>
using namespace std;
int n;
int m;
void solve() {
  cin >> n >> m;
  vector<pair<int, int>> a(m);
  for (auto&& i : a) {
    cin >> i.first >> i.second;
    i.first--;
  }
  sort(a.begin(), a.begin());
  string ans = string(n, '0');
  vector<int> can(n, -1);
  for (auto&& i : a) {
    if (can[i.first] > -1 && can[i.first] != i.second) {
      cout << -1 << '\n';
      return;
    }
    can[i.first] = i.second;
    ans[i.first] = i.second + '0';
  }
  if (n > 1 && ans[0] == '0') ans = "-1";
  cout << ans << '\n';
}
int main() {
  int t = 1;
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  while (t--) solve();
}
