#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, -1);
  bool cek = false;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    if (ans[s - 1] <= 9 && ans[s - 1] >= 0) {
      if (ans[s - 1] != c) {
        cek = true;
        break;
      }
    } else
      ans[s - 1] = c;
  }
  if (ans[0] == 0) cek = true;
  if (cek) {
    cout << "-1\n";
    return 0;
  }
  if (ans[0] == -1) ans[0] = 1;
  for (int i = 2; i <= n; i++)
    if (ans[i - 1] == -1) ans[i - 1] = 0;
  for (int i = 0; i < n; i++) cout << ans[i];
  cout << "\n";
  return 0;
}
