#include <bits/stdc++.h>
using namespace std;
void solve() {
  int n, m;
  cin >> n >> m;
  pair<int, int> sc[m];
  vector<int> res(n, 100001);
  for (unsigned long long int i = 0; i < m; i++) {
    cin >> sc[i].first >> sc[i].second;
    if (res[sc[i].first - 1] != 100001 &&
        res[sc[i].first - 1] != sc[i].second) {
      cout << -1;
      return;
    } else
      res[sc[i].first - 1] = min(res[sc[i].first - 1], sc[i].second);
  }
  int tp = 1, fg = false;
  for (unsigned long long int i = 0; i < n; i++) {
    if (!fg && res[i] != 100001) fg = true, tp = 0;
    if (res[i] == 100001) res[i] = tp;
  }
  if (res[0] == 0) {
    cout << -1;
    return;
  }
  for (unsigned long long int i = 0; i < n; i++) cout << res[i];
  return;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}
