#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  istream& in(cin);
  ostream& out(cout);
  int n, m, s, c;
  in >> n >> m;
  if (n == 1) {
    in >> s >> c;
    int C;
    for (int i = 0; i < (m - 1); ++i) {
      in >> s >> C;
      if (c != C) return puts("-1"), 0;
    }
    cout << c << endl;
    return 0;
  }
  vector<int> ans(n, -1);
  for (int i = 0; i < (m); ++i) {
    in >> s >> c;
    --s;
    if (s == 0 && c == 0) return puts("-1"), 0;
    if (ans[s] == -1)
      ans[s] = c;
    else if (ans[s] != c)
      return puts("-1"), 0;
  }
  for (int i = 1; i <= (n - 1); ++i)
    if (ans[i] < 0) ans[i] = 0;
  if (ans[0] < 0) ans[0] = 1;
  for (int i = 0; i < (n); ++i) cout << ans[i];
  cout << endl;
}
