#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using ipair = pair<int, int>;
int main() {
  int N, M;
  cin >> N >> M;
  vector<ipair> pa(M);
  for (int(i) = 0; (i) < (int)(M); (i)++) cin >> pa[i].first >> pa[i].second;
  sort(pa.begin(), pa.end(),
       [](const ipair& x, const ipair& y) { return x.first > y.first; });
  int ans = 0;
  int fin_flag = 0;
  for (int(i) = 0; (i) < (int)(M - 1); (i)++) {
    if (pa[i].first == pa[i + 1].first && pa[i].second != pa[i + 1].second) {
      fin_flag = 1;
      break;
    }
  }
  for (int(i) = 0; (i) < (int)(M); (i)++) {
    if (pa[i].first == 1 && pa[i].second == 0) {
      fin_flag = 1;
      break;
    }
  }
  if (fin_flag == 1)
    cout << "-1" << endl;
  else {
    ans += pa[0].second * pow(10, N - pa[0].first);
    for (int(i) = 1; (i) < (int)(M); (i)++) {
      if (pa[i].first != pa[i - 1].first) {
        ans += pa[i].second * pow(10, N - pa[i].first);
      }
    }
    if (ans / pow(10, N - 1) <= 0) ans += pow(10, N - 1);
    cout << ans << endl;
  }
}
