#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(10);
  int n, m;
  cin >> n >> m;
  int s, c;
  vector<int> a(n, 0);
  bool ans = true;
  for (int i = 0; i < (int)(m); i++) {
    cin >> s >> c;
    s--;
    if (a[s] != 0 && a[s] != c)
      ans = false;
    else
      a[s] = c;
  }
  if (a[0] == 0) ans = false;
  if (ans)
    for (auto p : a) cout << p;
  else
    cout << "-1";
  cout << "\n";
}
