#include <bits/stdc++.h>
using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;
int main() {
  int N, M;
  cin >> N >> M;
  map<int, int> digit2NumMap;
  for (int i = 0; i < M; ++i) {
    int si, ci;
    cin >> si >> ci;
    if (N > 1 && si == 1 && ci == 0) {
      cout << -1 << endl;
      return 0;
    }
    auto itr = digit2NumMap.find(si);
    if (itr == digit2NumMap.end()) {
      digit2NumMap[si] = ci;
    } else {
      if (ci != itr->second) {
        cout << -1 << endl;
        return 0;
      }
    }
  }
  int ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (digit2NumMap.find(i) == digit2NumMap.end()) {
      if (i == 1)
        ans += 1;
      else
        ans += 0;
    } else {
      ans += digit2NumMap[i];
    }
    ans *= 10;
  }
  ans /= 10;
  cout << ans << endl;
}
