#include <bits/stdc++.h>
using namespace std;
int main() {
  long long n, m;
  cin >> n >> m;
  vector<int> ans(n, 0);
  ans[0] = 1;
  vector<pair<int, int> > s(m);
  for (long long(i) = 0; (i) < (m); (i)++) {
    cin >> s[i].first >> s[i].second;
  }
  sort(s.begin(), s.end());
  for (long long(i) = 0; (i) < (m - 1); (i)++) {
    if (s[i].first == s[i + 1].first && s[i].second != s[i + 1].second) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long(i) = 0; (i) < (m); (i)++) {
    if (s[i].first == 1 && s[i].second == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
  }
  for (long long(i) = 0; (i) < (m); (i)++) {
    ans[s[i].first - 1] = s[i].second;
  }
  for (long long(i) = 0; (i) < (n); (i)++) {
    cout << ans[i];
  }
  cout << endl;
  return 0;
}
