#include <bits/stdc++.h>
using namespace std;
const int MAX = 100005;
const int MOD = 1000000007;
void solve() { return; }
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long n, m;
  cin >> n >> m;
  vector<long long> arr(n, 0);
  if (n != 1) arr[0] = 1;
  long long flag = 1;
  map<long long, long long> mp;
  for (int i = 0; i < m; i++) {
    long long s, c;
    cin >> s >> c;
    s--;
    arr[s] = c;
    if (!mp.count(s))
      mp[s] = c;
    else {
      if (mp[s] != c) flag = 0;
    }
  }
  if (arr[0] == 0) flag = 0;
  if (flag == 0)
    cout << "-1\n";
  else {
    long long ans = 0;
    for (int i = 0; i < n; i++) {
      ans = ans * 10 + arr[i];
    }
    cout << ans << endl;
  }
  return 0;
}
