#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e6;
const long long N = 1e3 + 7;
const long long mod = 1e9 + 7;
const long double eps = 1E-7;
int T = 1, mx, n, m, b, y, x, c, a;
int ans[10];
vector<long long> v, v1;
set<long long> st;
int main() {
  ios_base::sync_with_stdio(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    cin >> x >> y;
    mx = max(mx, x);
    if (!ans[x]) {
      ans[x] = y;
      continue;
    }
    ans[x] = min(ans[x], y);
  }
  if (n == 1) {
    cout << max(0, ans[1]);
    return 0;
  }
  if (!ans[1]) {
    cout << "-1";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    cout << ans[i];
  }
}
