#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> ans(n, 0);
  if (m == 0) {
    int temp = 1;
    for (long long i = 0; i < (long long)(n - 1); i++) temp *= 10;
    cout << temp << endl;
    return 0;
  }
  for (long long i = 0; i < (long long)(m); i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (ans.at(s) == 0)
      ans.at(s) = c;
    else if (ans.at(s) != c) {
      cout << -1 << endl;
      return 0;
    }
  }
  if (ans.at(0) == 0) {
    cout << -1 << endl;
    return 0;
  }
  int ansn = 0;
  for (long long i = 0; i < (long long)(n); i++) {
    ansn += ans.at(i);
    ansn *= 10;
  }
  ansn /= 10;
  while (ansn % 10 == 0) ansn /= 10;
  cout << ansn << endl;
}
