#include <bits/stdc++.h>
int mod = 1e9 + 7;
using namespace std;
class Solution {
 public:
  void solve() {
    int n, m;
    cin >> n >> m;
    int arr[n + 1], tmp1, tmp2;
    memset(arr, 0, sizeof(arr));
    for (int i = 0; i < m; i++) {
      cin >> tmp1 >> tmp2;
      if (arr[tmp1] == 0 || tmp2 < arr[tmp1]) arr[tmp1] = tmp2;
    }
    if (n == 1) {
      cout << arr[1] << '\n';
    } else {
      if (arr[1] == 0) {
        cout << -1 << '\n';
      } else {
        for (int i = 1; i <= n; i++) {
          cout << arr[i];
        }
        cout << '\n';
      }
    }
  }
};
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  clock_t start_t, end_t;
  double total_t;
  start_t = clock();
  Solution sol;
  sol.solve();
  end_t = clock();
  total_t = 1e3 * (double)(end_t - start_t) / CLOCKS_PER_SEC;
  cerr << "\nRunTime: " << total_t << "ms" << '\n';
  return 0;
}
