#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(15);
  int N, M;
  cin >> N >> M;
  vector<int> A(N + 1, -1);
  for (int i = (0); i < (M); ++i) {
    int s, c;
    cin >> s >> c;
    if (A[s] == -1) {
      A[s] = c;
    } else if (A[s] != c) {
      cout << -1 << "\n";
      return 0;
    }
  }
  string ans = "";
  for (int i = N; i > 0; i--) {
    if (A[i] >= 0) {
      ans = to_string(A[i]) + ans;
    } else {
      ans = "0" + ans;
    }
  }
  if (N > 1 && count(ans.begin(), ans.end(), '0') == N) {
    ans = "-1";
  }
  cout << stoi(ans) << "\n";
}
