#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, m;
  cin >> n >> m;
  int map[]{-1, -1, -1};
  bool is_error = false;
  for (int i = 0; i < (m); ++i) {
    int x, y;
    cin >> x >> y;
    --x;
    if (map[x] != -1 && map[x] != y) is_error = true;
    if (n > 1 && x == 0 && y == 0) is_error = true;
    map[x] = y;
  }
  if (is_error) {
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for (int i = 0; i < (n); ++i) {
    ans += map[i] == -1 ? 0 : pow(10, n - i - 1) * map[i];
  }
  cout << ans << endl;
}
