#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n, m;
  cin >> n >> m;
  string ans = string(n, '0');
  vector<bool> used(10, false);
  int s, c;
  for (int i = 0; i < m; ++i) {
    cin >> s >> c;
    if (s == 1 && c == 0) {
      cout << -1 << endl;
      return 0;
    } else {
      if (used[s] && int(ans[s - 1] - '0') != c) {
        cout << -1 << endl;
        return 0;
      } else {
        used[s] = true;
        ans[s - 1] = char(c + '0');
      }
    }
  }
  if (ans[0] == '0') ans[0] = '1';
  cout << ans << endl;
}
